Merge from booking branch
This commit is contained in:
parent
25906d0227
commit
9a2652739b
266 changed files with 12833 additions and 2337 deletions
419
booking/Controllers/AccountController.cs
Normal file
419
booking/Controllers/AccountController.cs
Normal file
|
|
@ -0,0 +1,419 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Profile;
|
||||
using System.Web.Security;
|
||||
using Yavsc;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using Yavsc.Helpers;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Model.Circles;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Configuration;
|
||||
using Yavsc.Model;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Account controller.
|
||||
/// </summary>
|
||||
public class AccountController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Avatar the specified user.
|
||||
/// </summary>
|
||||
/// <param name="id">User.</param>
|
||||
[AcceptVerbs (HttpVerbs.Get)]
|
||||
public ActionResult Avatar (string id)
|
||||
{
|
||||
string avatarLocation = Url.AvatarUrl (id);
|
||||
WebRequest wr = WebRequest.Create (avatarLocation);
|
||||
FileContentResult res;
|
||||
using (WebResponse resp = wr.GetResponse ()) {
|
||||
using (Stream str = resp.GetResponseStream ()) {
|
||||
byte[] content = new byte[str.Length];
|
||||
str.Read (content, 0, (int)str.Length);
|
||||
res = File (content, resp.ContentType);
|
||||
wr.Abort ();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
// TODO [ValidateAntiForgeryToken]
|
||||
/// <summary>
|
||||
/// Does login.
|
||||
/// </summary>
|
||||
/// <returns>The login.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[HttpPost,ValidateAntiForgeryToken]
|
||||
public ActionResult Login (LoginModel model, string returnUrl)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
if (Membership.ValidateUser (model.UserName, model.Password)) {
|
||||
FormsAuthentication.SetAuthCookie (model.UserName, model.RememberMe);
|
||||
if (returnUrl != null)
|
||||
return Redirect (returnUrl);
|
||||
else
|
||||
return View ("Index");
|
||||
} else {
|
||||
ModelState.AddModelError ("UserName", "The user name or password provided is incorrect.");
|
||||
}
|
||||
}
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
return View (model);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Login the specified returnUrl.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[HttpGet]
|
||||
public ActionResult Login (string returnUrl)
|
||||
{
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the registration form.
|
||||
/// </summary>
|
||||
/// <returns>The register.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
public ActionResult GetRegister(RegisterViewModel model, string returnUrl)
|
||||
{
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
return View ("Register",model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register the specified model and returnUrl.
|
||||
/// </summary>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[HttpPost]
|
||||
public ActionResult Register (RegisterViewModel model, string returnUrl)
|
||||
{
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
|
||||
if (ModelState.IsValid) {
|
||||
if (model.ConfirmPassword != model.Password) {
|
||||
ModelState.AddModelError ("ConfirmPassword", "Veuillez confirmer votre mot de passe");
|
||||
return View (model);
|
||||
}
|
||||
|
||||
MembershipCreateStatus mcs;
|
||||
var user = Membership.CreateUser (
|
||||
model.UserName,
|
||||
model.Password,
|
||||
model.Email,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
out mcs);
|
||||
switch (mcs) {
|
||||
case MembershipCreateStatus.DuplicateEmail:
|
||||
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||
"à un compte utilisateur existant");
|
||||
return View (model);
|
||||
case MembershipCreateStatus.DuplicateUserName:
|
||||
ModelState.AddModelError ("UserName", "Ce nom d'utilisateur est " +
|
||||
"déjà enregistré");
|
||||
return View (model);
|
||||
case MembershipCreateStatus.Success:
|
||||
Url.SendActivationMessage (user);
|
||||
ViewData ["username"] = user.UserName;
|
||||
ViewData ["email"] = user.Email;
|
||||
return View ("RegistrationPending");
|
||||
default:
|
||||
ViewData ["Error"] = "Une erreur inattendue s'est produite" +
|
||||
"a l'enregistrement de votre compte utilisateur" +
|
||||
string.Format ("({0}).", mcs.ToString ()) +
|
||||
"Veuillez pardonner la gêne" +
|
||||
"occasionnée";
|
||||
return View (model);
|
||||
}
|
||||
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the password success.
|
||||
/// </summary>
|
||||
/// <returns>The password success.</returns>
|
||||
public ActionResult ChangePasswordSuccess ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Changes the password.
|
||||
/// </summary>
|
||||
/// <returns>The password.</returns>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public ActionResult ChangePassword ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister the specified id and confirmed.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="confirmed">If set to <c>true</c> confirmed.</param>
|
||||
[Authorize]
|
||||
public ActionResult Unregister (string id, bool confirmed = false)
|
||||
{
|
||||
ViewData ["UserName"] = id;
|
||||
if (!confirmed)
|
||||
return View ();
|
||||
string logged = this.User.Identity.Name;
|
||||
if (logged != id)
|
||||
if (!Roles.IsUserInRole ("Admin"))
|
||||
throw new Exception ("Unregister another user");
|
||||
|
||||
Membership.DeleteUser (
|
||||
Membership.GetUser ().UserName);
|
||||
return RedirectToAction ("Index", "Home");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Changes the password.
|
||||
/// </summary>
|
||||
/// <returns>The password.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult ChangePassword (ChangePasswordModel model)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
|
||||
// ChangePassword will throw an exception rather
|
||||
// than return false in certain failure scenarios.
|
||||
bool changePasswordSucceeded = false;
|
||||
try {
|
||||
MembershipUserCollection users =
|
||||
Membership.FindUsersByName (model.Username);
|
||||
if (users.Count > 0) {
|
||||
MembershipUser user = Membership.GetUser (model.Username, true);
|
||||
|
||||
changePasswordSucceeded = user.ChangePassword (model.OldPassword, model.NewPassword);
|
||||
} else {
|
||||
changePasswordSucceeded = false;
|
||||
ModelState.AddModelError ("Username", "The user name not found.");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ViewData ["Error"] = ex.ToString ();
|
||||
}
|
||||
|
||||
if (changePasswordSucceeded) {
|
||||
return RedirectToAction ("ChangePasswordSuccess");
|
||||
} else {
|
||||
ModelState.AddModelError ("Password", "The current password is incorrect or the new password is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
return View (model);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Profile the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public ActionResult Profile (string id)
|
||||
{
|
||||
if (id == null)
|
||||
id = Membership.GetUser ().UserName;
|
||||
ViewData ["UserName"] = id;
|
||||
ProfileEdition model = new ProfileEdition (ProfileBase.Create (id));
|
||||
model.RememberMe = FormsAuthentication.GetAuthCookie (id, true) == null;
|
||||
return View (model);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Profile the specified id, model and AvatarFile.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="AvatarFile">Avatar file.</param>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult Profile (string id, ProfileEdition model, HttpPostedFileBase AvatarFile)
|
||||
{
|
||||
string logdu = User.Identity.Name;
|
||||
if (string.IsNullOrWhiteSpace (id)) {
|
||||
if (string.IsNullOrWhiteSpace (model.UserName)) {
|
||||
model.UserName = logdu;
|
||||
return View (model);
|
||||
} else {
|
||||
id = logdu;
|
||||
}
|
||||
}
|
||||
ViewData ["UserName"] = id;
|
||||
bool editsTheUserName = model.NewUserName!=null&&(string.Compare(id,model.NewUserName)!=0);
|
||||
// Checks authorisation
|
||||
if (logdu!=id)
|
||||
if (!Roles.IsUserInRole ("Admin"))
|
||||
if (!Roles.IsUserInRole ("FrontOffice"))
|
||||
throw new UnauthorizedAccessException ("Your are not authorized to modify this profile");
|
||||
// checks availability of a new username
|
||||
if (editsTheUserName)
|
||||
if (!UserManager.IsAvailable (model.NewUserName))
|
||||
ModelState.AddModelError ("UserName",
|
||||
string.Format (
|
||||
LocalizedText.DuplicateUserName,
|
||||
model.NewUserName
|
||||
));
|
||||
if (AvatarFile != null) {
|
||||
// if said valid, move as avatar file
|
||||
// else invalidate the model
|
||||
if (AvatarFile.ContentType == "image/png") {
|
||||
string avdir = Server.MapPath (YavscHelpers.AvatarDir);
|
||||
var di = new DirectoryInfo (avdir);
|
||||
if (!di.Exists)
|
||||
di.Create ();
|
||||
string avpath = Path.Combine (avdir, id + ".png");
|
||||
AvatarFile.SaveAs (avpath);
|
||||
model.avatar = Url.Content( YavscHelpers.AvatarDir + "/" + id + ".png");
|
||||
} else
|
||||
ModelState.AddModelError ("Avatar",
|
||||
string.Format ("Image type {0} is not supported (suported formats : {1})",
|
||||
AvatarFile.ContentType, "image/png"));
|
||||
}
|
||||
if (ModelState.IsValid) {
|
||||
ProfileBase prf = ProfileBase .Create (id);
|
||||
prf.SetPropertyValue ("Name", model.Name);
|
||||
prf.SetPropertyValue ("BlogVisible", model.BlogVisible);
|
||||
prf.SetPropertyValue ("BlogTitle", model.BlogTitle);
|
||||
if (AvatarFile != null) {
|
||||
prf.SetPropertyValue ("Avatar", model.avatar);
|
||||
} else {
|
||||
var av = prf.GetPropertyValue ("Avatar");
|
||||
if (av != null)
|
||||
model.avatar = av as string;
|
||||
}
|
||||
prf.SetPropertyValue ("Address", model.Address);
|
||||
prf.SetPropertyValue ("CityAndState", model.CityAndState);
|
||||
prf.SetPropertyValue ("Country", model.Country);
|
||||
prf.SetPropertyValue ("ZipCode", model.ZipCode);
|
||||
prf.SetPropertyValue ("WebSite", model.WebSite);
|
||||
prf.SetPropertyValue ("Name", model.Name);
|
||||
prf.SetPropertyValue ("Phone", model.Phone);
|
||||
prf.SetPropertyValue ("Mobile", model.Mobile);
|
||||
prf.SetPropertyValue ("BankCode", model.BankCode);
|
||||
prf.SetPropertyValue ("IBAN", model.IBAN);
|
||||
prf.SetPropertyValue ("BIC", model.BIC);
|
||||
prf.SetPropertyValue ("WicketCode", model.WicketCode);
|
||||
prf.SetPropertyValue ("AccountNumber", model.AccountNumber);
|
||||
prf.SetPropertyValue ("BankedKey", model.BankedKey);
|
||||
prf.SetPropertyValue ("gcalid", model.GoogleCalendar);
|
||||
prf.Save ();
|
||||
|
||||
if (editsTheUserName) {
|
||||
UserManager.ChangeName (id, model.NewUserName);
|
||||
FormsAuthentication.SetAuthCookie (model.NewUserName, model.RememberMe);
|
||||
model.UserName = model.NewUserName;
|
||||
}
|
||||
YavscHelpers.Notify(ViewData, "Profile enregistré"+((editsTheUserName)?", nom public inclu.":""));
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
/// <summary>
|
||||
/// Circles this instance.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public ActionResult Circles ()
|
||||
{
|
||||
string user = Membership.GetUser ().UserName;
|
||||
ViewData["Circles"] = CircleManager.DefaultProvider.List (user);
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logout the specified returnUrl.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[Authorize]
|
||||
public ActionResult Logout (string returnUrl)
|
||||
{
|
||||
FormsAuthentication.SignOut ();
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Losts the password.
|
||||
/// </summary>
|
||||
/// <returns>The password.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
public ActionResult ResetPassword(LostPasswordModel model)
|
||||
{
|
||||
if (Request.HttpMethod == "POST") {
|
||||
StringDictionary errors;
|
||||
MembershipUser user;
|
||||
YavscHelpers.ValidatePasswordReset (model, out errors, out user);
|
||||
foreach (string key in errors.Keys)
|
||||
ModelState.AddModelError (key, errors [key]);
|
||||
|
||||
if (user != null && ModelState.IsValid)
|
||||
Url.SendActivationMessage (user);
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the specified id and key.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="key">Key.</param>
|
||||
[HttpGet]
|
||||
public ActionResult Validate (string id, string key)
|
||||
{
|
||||
MembershipUser u = Membership.GetUser (id, false);
|
||||
if (u == null) {
|
||||
YavscHelpers.Notify( ViewData,
|
||||
string.Format ("Cet utilisateur n'existe pas ({0})", id));
|
||||
} else if (u.ProviderUserKey.ToString () == key) {
|
||||
if (u.IsApproved) {
|
||||
YavscHelpers.Notify( ViewData,
|
||||
string.Format ("Votre compte ({0}) est déjà validé.", id));
|
||||
} else {
|
||||
u.IsApproved = true;
|
||||
Membership.UpdateUser (u);
|
||||
YavscHelpers.Notify( ViewData,
|
||||
string.Format ("La création de votre compte ({0}) est validée.", id));
|
||||
}
|
||||
} else
|
||||
YavscHelpers.Notify( ViewData, "La clé utilisée pour valider ce compte est incorrecte" );
|
||||
return View ();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
324
booking/Controllers/AdminController.cs
Normal file
324
booking/Controllers/AdminController.cs
Normal file
|
|
@ -0,0 +1,324 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using Yavsc.Model.Admin;
|
||||
using Yavsc.Admin;
|
||||
using System.IO;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Admin controller.
|
||||
/// Only Admin members should be allowed to use it.
|
||||
/// </summary>
|
||||
public class AdminController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index()
|
||||
{
|
||||
// FIXME do this in a new installation script.
|
||||
if (!Roles.RoleExists (_adminRoleName)) {
|
||||
Roles.CreateRole (_adminRoleName);
|
||||
YavscHelpers.Notify (ViewData, _adminRoleName + " " + LocalizedText.role_created);
|
||||
}
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Inits the db.
|
||||
/// In order this action succeds,
|
||||
/// there must not exist any administrator,
|
||||
/// nor Admin group.
|
||||
/// </summary>
|
||||
/// <returns>The db.</returns>
|
||||
/// <param name="datac">Datac.</param>
|
||||
/// <param name="doInit">Do init.</param>
|
||||
public ActionResult InitDb(DataAccess datac, string doInit)
|
||||
{
|
||||
if (doInit=="on") {
|
||||
if (ModelState.IsValid) {
|
||||
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
|
||||
DataManager mgr = new DataManager (datac);
|
||||
TaskOutput tcdb = mgr.CreateDb ();
|
||||
ViewData ["DbName"] = datac.DbName;
|
||||
ViewData ["DbUser"] = datac.DbUser;
|
||||
ViewData ["Host"] = datac.Host;
|
||||
ViewData ["Port"] = datac.Port;
|
||||
return View ("Created", tcdb);
|
||||
}
|
||||
}
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Backups the specified model.
|
||||
/// </summary>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult Backups(DataAccess model)
|
||||
{
|
||||
return View (model);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates the backup.
|
||||
/// </summary>
|
||||
/// <returns>The backup.</returns>
|
||||
/// <param name="datac">Datac.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult CreateBackup(DataAccess datac)
|
||||
{
|
||||
if (datac != null) {
|
||||
if (ModelState.IsValid) {
|
||||
if (string.IsNullOrEmpty (datac.Password))
|
||||
ModelState.AddModelError ("Password", "Invalid passord");
|
||||
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
|
||||
DataManager ex = new DataManager (datac);
|
||||
Export e = ex.CreateBackup ();
|
||||
if (e.ExitCode > 0)
|
||||
ModelState.AddModelError ("Password", "Operation Failed");
|
||||
return View ("BackupCreated", e);
|
||||
}
|
||||
} else {
|
||||
datac = new DataAccess ();
|
||||
}
|
||||
return View (datac);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates the user backup.
|
||||
/// </summary>
|
||||
/// <returns>The user backup.</returns>
|
||||
/// <param name="datac">Datac.</param>
|
||||
/// <param name="username">Username.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult CreateUserBackup(DataAccess datac,string username)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Upgrade the specified datac.
|
||||
/// </summary>
|
||||
/// <param name="datac">Datac.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult Upgrade(DataAccess datac) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Restore the specified datac, backupName and dataOnly.
|
||||
/// </summary>
|
||||
/// <param name="datac">Datac.</param>
|
||||
/// <param name="backupName">Backup name.</param>
|
||||
/// <param name="dataOnly">If set to <c>true</c> data only.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult Restore(DataAccess datac,string backupName,bool dataOnly=true)
|
||||
{
|
||||
ViewData ["BackupName"] = backupName;
|
||||
if (ModelState.IsValid) {
|
||||
// TODO BETTER
|
||||
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
|
||||
DataManager mgr = new DataManager (datac);
|
||||
ViewData ["BackupName"] = backupName;
|
||||
ViewData ["DataOnly"] = dataOnly;
|
||||
|
||||
TaskOutput t = mgr.Restore (
|
||||
Path.Combine(new FileInfo(datac.BackupPrefix).DirectoryName,
|
||||
backupName),dataOnly);
|
||||
return View ("Restored", t);
|
||||
}
|
||||
BuildBackupList (datac);
|
||||
return View (datac);
|
||||
}
|
||||
private void BuildBackupList(DataAccess datac)
|
||||
{
|
||||
// build ViewData ["Backups"];
|
||||
string bckd=Server.MapPath (datac.BackupPrefix);
|
||||
DirectoryInfo di = new DirectoryInfo (new FileInfo(bckd).DirectoryName);
|
||||
List<string> bks = new List<string> ();
|
||||
foreach (FileInfo ti in di.GetFiles("*.tar"))
|
||||
bks.Add (ti.Name);
|
||||
ViewData ["Backups"] = bks.ToArray ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes from role.
|
||||
/// </summary>
|
||||
/// <returns>The from role.</returns>
|
||||
/// <param name="username">Username.</param>
|
||||
/// <param name="rolename">Rolename.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)
|
||||
{
|
||||
Roles.RemoveUserFromRole(username,rolename);
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the user.
|
||||
/// </summary>
|
||||
/// <returns>The user.</returns>
|
||||
/// <param name="username">Username.</param>
|
||||
/// <param name="submitbutton">Submitbutton.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult RemoveUser (string username, string submitbutton)
|
||||
{
|
||||
ViewData ["usertoremove"] = username;
|
||||
if (submitbutton == "Supprimer") {
|
||||
Membership.DeleteUser (username);
|
||||
YavscHelpers.Notify(ViewData, string.Format("utilisateur \"{0}\" supprimé",username));
|
||||
ViewData ["usertoremove"] = null;
|
||||
}
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the role.
|
||||
/// </summary>
|
||||
/// <returns>The role.</returns>
|
||||
/// <param name="rolename">Rolename.</param>
|
||||
/// <param name="submitbutton">Submitbutton.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult RemoveRole (string rolename, string submitbutton)
|
||||
{
|
||||
if (submitbutton == "Supprimer")
|
||||
{
|
||||
Roles.DeleteRole(rolename);
|
||||
}
|
||||
return RedirectToAction("RoleList");
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the role query.
|
||||
/// </summary>
|
||||
/// <returns>The role query.</returns>
|
||||
/// <param name="rolename">Rolename.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult RemoveRoleQuery(string rolename)
|
||||
{
|
||||
ViewData["roletoremove"] = rolename;
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the user query.
|
||||
/// </summary>
|
||||
/// <returns>The user query.</returns>
|
||||
/// <param name="username">Username.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
public ActionResult RemoveUserQuery(string username)
|
||||
{
|
||||
ViewData["usertoremove"] = username;
|
||||
return UserList();
|
||||
}
|
||||
|
||||
|
||||
//TODO no more than pageSize results per page
|
||||
/// <summary>
|
||||
/// User list.
|
||||
/// </summary>
|
||||
/// <returns>The list.</returns>
|
||||
[Authorize()]
|
||||
public ActionResult UserList ()
|
||||
{
|
||||
MembershipUserCollection c = Membership.GetAllUsers ();
|
||||
return View (c);
|
||||
}
|
||||
[Authorize()]
|
||||
public ActionResult UsersInRole (string rolename)
|
||||
{
|
||||
if (rolename == null)
|
||||
rolename = "Admin";
|
||||
ViewData ["RoleName"] = rolename;
|
||||
ViewData ["Roles"] = Roles.GetAllRoles ();
|
||||
ViewData ["UsersInRole"] = Roles.GetUsersInRole (rolename);
|
||||
return View ();
|
||||
}
|
||||
|
||||
[Authorize()]
|
||||
public ActionResult UserRoles (string username)
|
||||
{
|
||||
ViewData ["AllRoles"] = Roles.GetAllRoles ();
|
||||
if (username == null)
|
||||
username = User.Identity.Name;
|
||||
ViewData ["UserName"] = username;
|
||||
ViewData ["UsersRoles"] = Roles.GetRolesForUser (username);
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// a form to add a role
|
||||
/// </summary>
|
||||
/// <returns>The role.</returns>
|
||||
[Authorize(Roles="Admin"),HttpGet]
|
||||
public ActionResult AddRole ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new role.
|
||||
/// </summary>
|
||||
/// <returns>The add role.</returns>
|
||||
/// <param name="rolename">Rolename.</param>
|
||||
[Authorize(Roles="Admin"),HttpPost]
|
||||
public ActionResult AddRole (string rolename)
|
||||
{
|
||||
Roles.CreateRole(rolename);
|
||||
YavscHelpers.Notify(ViewData, LocalizedText.role_created+ " : "+rolename);
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the roles list.
|
||||
/// </summary>
|
||||
/// <returns>The list.</returns>
|
||||
[Authorize()]
|
||||
public ActionResult RoleList ()
|
||||
{
|
||||
return View (Roles.GetAllRoles ());
|
||||
}
|
||||
|
||||
private const string _adminRoleName = "Admin";
|
||||
|
||||
/// <summary>
|
||||
/// Assing the Admin role to the specified user in model.
|
||||
/// </summary>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize()]
|
||||
public ActionResult Admin (NewAdminModel model)
|
||||
{
|
||||
// ASSERT (Roles.RoleExists (adminRoleName))
|
||||
string [] admins = Roles.GetUsersInRole (_adminRoleName);
|
||||
string currentUser = Membership.GetUser ().UserName;
|
||||
List<SelectListItem> users = new List<SelectListItem> ();
|
||||
foreach (MembershipUser u in Membership.GetAllUsers ()) {
|
||||
var i = new SelectListItem ();
|
||||
i.Text = string.Format ("{0} <{1}>", u.UserName, u.Email);
|
||||
i.Value = u.UserName;
|
||||
users.Add (i);
|
||||
}
|
||||
ViewData ["admins"] = admins;
|
||||
ViewData ["useritems"] = users;
|
||||
if (ModelState.IsValid) {
|
||||
Roles.AddUserToRole (model.UserName, _adminRoleName);
|
||||
YavscHelpers.Notify(ViewData, model.UserName + " "+LocalizedText.was_added_to_the_role+" '" + _adminRoleName + "'");
|
||||
} else {
|
||||
if (admins.Length > 0) {
|
||||
if (! admins.Contains (Membership.GetUser ().UserName)) {
|
||||
ModelState.Remove("UserName");
|
||||
ModelState.AddModelError("UserName",LocalizedText.younotadmin+"!");
|
||||
return View ("Index");
|
||||
}
|
||||
} else {
|
||||
// No admin, gives the Admin Role to the current user
|
||||
Roles.AddUserToRole (currentUser, _adminRoleName);
|
||||
admins = new string[] { currentUser };
|
||||
YavscHelpers.Notify(ViewData, string.Format (
|
||||
LocalizedText.was_added_to_the_empty_role,
|
||||
currentUser, _adminRoleName));
|
||||
}
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
booking/Controllers/BackOfficeController.cs
Normal file
25
booking/Controllers/BackOfficeController.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Admin;
|
||||
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Back office controller.
|
||||
/// </summary>
|
||||
public class BackOfficeController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
[Authorize(Roles="Admin,Providers")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
}
|
||||
412
booking/Controllers/BlogsController.cs
Normal file
412
booking/Controllers/BlogsController.cs
Normal file
|
|
@ -0,0 +1,412 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Profile;
|
||||
using System.Web.Security;
|
||||
using Npgsql.Web.Blog;
|
||||
using Yavsc;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Model.Blogs;
|
||||
using Yavsc.ApiControllers;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using System.Net;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Model.Circles;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Blogs controller.
|
||||
/// </summary>
|
||||
public class BlogsController : Controller
|
||||
{
|
||||
private string sitename =
|
||||
WebConfigurationManager.AppSettings ["Name"];
|
||||
|
||||
/// <summary>
|
||||
/// Index the specified title, pageIndex and pageSize.
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
public ActionResult Index (string title, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
if (title != null)
|
||||
return Title (title, pageIndex, pageSize);
|
||||
|
||||
return BlogList (pageIndex, pageSize);
|
||||
}
|
||||
/// <summary>
|
||||
/// Chooses the media.
|
||||
/// </summary>
|
||||
/// <returns>The media.</returns>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult ChooseMedia(long postid)
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Blogs the list.
|
||||
/// </summary>
|
||||
/// <returns>The list.</returns>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
public ActionResult BlogList (int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalRecords;
|
||||
var bs = BlogManager.LastPosts (pageIndex, pageSize, out totalRecords);
|
||||
ViewData ["ResultCount"] = totalRecords;
|
||||
ViewData ["PageSize"] = pageSize;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
var bec = new BlogEntryCollection (bs);
|
||||
return View ("Index", bec );
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Title the specified title, pageIndex and pageSize.
|
||||
/// </summary>
|
||||
/// <param name="id">Title.</param>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
///
|
||||
[HttpGet]
|
||||
public ActionResult Title (string title, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int recordCount;
|
||||
MembershipUser u = Membership.GetUser ();
|
||||
string username = u == null ? null : u.UserName;
|
||||
FindBlogEntryFlags sf = FindBlogEntryFlags.MatchTitle;
|
||||
BlogEntryCollection c =
|
||||
BlogManager.FindPost (username, title, sf, pageIndex, pageSize, out recordCount);
|
||||
var utc = new UTBlogEntryCollection (title);
|
||||
utc.AddRange (c);
|
||||
ViewData ["RecordCount"] = recordCount;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
ViewData ["PageSize"] = pageSize;
|
||||
return View ("Title", utc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Users the posts.
|
||||
/// </summary>
|
||||
/// <returns>The posts.</returns>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
[HttpGet]
|
||||
public ActionResult UserPosts (string user, string title=null, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
if (title != null) return UserPost (user, title, pageIndex, pageSize);
|
||||
int recordcount=0;
|
||||
MembershipUser u = Membership.GetUser ();
|
||||
FindBlogEntryFlags sf = FindBlogEntryFlags.MatchUserName;
|
||||
ViewData ["SiteName"] = sitename;
|
||||
ViewData ["BlogUser"] = user;
|
||||
string readersName = null;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
ViewData ["pageSize"] = pageSize;
|
||||
// displays invisible items when the logged user is also the author
|
||||
if (u != null) {
|
||||
if (u.UserName == user || Roles.IsUserInRole ("Admin"))
|
||||
sf |= FindBlogEntryFlags.MatchInvisible;
|
||||
readersName = u.UserName;
|
||||
if (user == null)
|
||||
user = u.UserName;
|
||||
}
|
||||
// find entries
|
||||
BlogEntryCollection c =
|
||||
BlogManager.FindPost (readersName, user, sf, pageIndex, pageSize, out recordcount);
|
||||
// Get author's meta data
|
||||
var pr = ProfileBase.Create (user);
|
||||
if (pr != null) {
|
||||
Profile bupr = new Profile (pr);
|
||||
ViewData ["BlogUserProfile"] = bupr;
|
||||
|
||||
// Inform of listing meta data
|
||||
ViewData ["BlogTitle"] = bupr.BlogTitle;
|
||||
ViewData ["Avatar"] = bupr.avatar;
|
||||
}
|
||||
ViewData ["RecordCount"] = recordcount;
|
||||
UUBlogEntryCollection uuc = new UUBlogEntryCollection (user, c);
|
||||
return View ("UserPosts", uuc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the comment.
|
||||
/// </summary>
|
||||
/// <returns>The comment.</returns>
|
||||
/// <param name="cmtid">Cmtid.</param>
|
||||
[Authorize(Roles="Blogger")]
|
||||
public ActionResult RemoveComment (long cmtid)
|
||||
{
|
||||
long postid = BlogManager.RemoveComment (cmtid);
|
||||
return GetPost (postid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the post.
|
||||
/// </summary>
|
||||
/// <returns>The post.</returns>
|
||||
/// <param name="postid">Postid.</param>
|
||||
public ActionResult GetPost (long postid)
|
||||
{
|
||||
ViewData ["id"] = postid;
|
||||
BlogEntry e = BlogManager.GetForReading (postid);
|
||||
UUTBlogEntryCollection c = new UUTBlogEntryCollection (e.Author,e.Title);
|
||||
c.Add (e);
|
||||
ViewData ["user"] = c.Author;
|
||||
ViewData ["title"] = c.Title;
|
||||
Profile pr = new Profile (ProfileBase.Create (c.Author));
|
||||
if (pr == null)
|
||||
// the owner's profile must exist
|
||||
// in order to publish its bills
|
||||
return View ("NotAuthorized");
|
||||
ViewData ["BlogUserProfile"] = pr;
|
||||
ViewData ["Avatar"] = pr.avatar;
|
||||
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||
return View ("UserPost",c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Users the post.
|
||||
/// Assume that :
|
||||
/// * bec.Count > O
|
||||
/// * bec.All(x=>x.Author == bec[0].Author) ;
|
||||
/// </summary>
|
||||
/// <returns>The post.</returns>
|
||||
/// <param name="bec">Bec.</param>
|
||||
private ActionResult UserPost (UUTBlogEntryCollection bec)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
if (bec.Count > 0) {
|
||||
Profile pr = new Profile (ProfileBase.Create (bec.Author));
|
||||
if (pr == null)
|
||||
// the owner's profile must exist
|
||||
// in order to publish its bills
|
||||
// This should'nt occur, as long as
|
||||
// a profile must exist for each one of
|
||||
// existing user record in data base
|
||||
// and each post is deleted with user deletion
|
||||
// a post => an author => a profile
|
||||
throw new Exception("Unexpected error retreiving author's profile");
|
||||
ViewData ["BlogUserProfile"] = pr;
|
||||
ViewData ["Avatar"] = pr.avatar;
|
||||
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||
MembershipUser u = Membership.GetUser ();
|
||||
|
||||
ViewData ["Author"] = bec.Author;
|
||||
if (!pr.BlogVisible) {
|
||||
// only deliver to admins or owner
|
||||
if (u == null)
|
||||
return View ("NotAuthorized");
|
||||
else {
|
||||
if (u.UserName != bec.Author)
|
||||
if (!Roles.IsUserInRole (u.UserName, "Admin"))
|
||||
return View ("NotAuthorized");
|
||||
}
|
||||
}
|
||||
if (u == null || (u.UserName != bec.Author) && !Roles.IsUserInRole (u.UserName, "Admin")) {
|
||||
// Filer on allowed posts
|
||||
BlogEntryCollection filtered = bec.FilterFor((u == null)?null : u.UserName);
|
||||
UUTBlogEntryCollection nbec = new UUTBlogEntryCollection (bec.Author, bec.Title);
|
||||
nbec.AddRange (filtered);
|
||||
View ("UserPost",nbec);
|
||||
}
|
||||
}
|
||||
return View ("UserPost",bec);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Users the post.
|
||||
/// </summary>
|
||||
/// <returns>The post.</returns>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="pageIndex">Page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
public ActionResult UserPost (string user, string title, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
ViewData ["user"] = user;
|
||||
ViewData ["title"] = title;
|
||||
ViewData ["PageIndex"] = pageIndex;
|
||||
ViewData ["pageSize"] = pageSize;
|
||||
var pb = ProfileBase.Create (user);
|
||||
if (pb == null)
|
||||
// the owner's profile must exist
|
||||
// in order to publish its bills
|
||||
return View ("NotAuthorized");
|
||||
Profile pr = new Profile (pb);
|
||||
ViewData ["BlogUserProfile"] = pr;
|
||||
ViewData ["Avatar"] = pr.avatar;
|
||||
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||
UUTBlogEntryCollection c = new UUTBlogEntryCollection (user, title);
|
||||
c.AddRange ( BlogManager.FilterOnReadAccess (BlogManager.GetPost (user, title)));
|
||||
return View ("UserPost",c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Post the specified title.
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
[Authorize(Roles="Blogger")]
|
||||
public ActionResult Post (string title)
|
||||
{
|
||||
string un = Membership.GetUser ().UserName;
|
||||
if (String.IsNullOrEmpty (title))
|
||||
title = "";
|
||||
ViewData ["SiteName"] = sitename;
|
||||
ViewData ["Author"] = un;
|
||||
ViewData ["AllowedCircles"] = CircleManager.DefaultProvider.List (un)
|
||||
.Select (x => new SelectListItem {
|
||||
Value = x.Id.ToString(),
|
||||
Text = x.Title
|
||||
});
|
||||
|
||||
return View ("Edit", new BlogEntry { Title = title, Author = un });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the edit.
|
||||
/// </summary>
|
||||
/// <returns>The edit.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize(Roles="Blogger")]
|
||||
public ActionResult ValidateEdit (BlogEntry model)
|
||||
{
|
||||
ViewData ["SiteName"] = sitename;
|
||||
ViewData ["Author"] = Membership.GetUser ().UserName;
|
||||
if (ModelState.IsValid) {
|
||||
if (model.Id != 0) {
|
||||
// ensures rights to update
|
||||
BlogManager.GetForEditing (model.Id, true);
|
||||
BlogManager.UpdatePost (model.Id, model.Title, model.Content, model.Visible, model.AllowedCircles);
|
||||
|
||||
}
|
||||
else
|
||||
model.Id = BlogManager.Post (model.Author, model.Title, model.Content, model.Visible, model.AllowedCircles);
|
||||
if (model.Photo != null)
|
||||
BlogManager.UpdatePostPhoto (model.Id, model.Photo);
|
||||
return RedirectToAction ("Title", new { title = model.Title });
|
||||
}
|
||||
ViewData ["AllowedCircles"] =
|
||||
CircleManager.DefaultProvider.List (
|
||||
Membership.GetUser ().UserName).Select (x => new SelectListItem {
|
||||
Value = x.Id.ToString(),
|
||||
Text = x.Title,
|
||||
Selected = model.AllowedCircles.Contains (x.Id)
|
||||
});
|
||||
return View ("Edit", model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit the specified bill
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
[Authorize(Roles="Blogger")]
|
||||
public ActionResult Edit (long postid)
|
||||
{
|
||||
|
||||
BlogEntry e = BlogManager.GetForEditing (postid);
|
||||
string user = Membership.GetUser ().UserName;
|
||||
Profile pr = new Profile (ProfileBase.Create(e.Author));
|
||||
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||
ViewData ["LOGIN"] = user;
|
||||
ViewData ["Id"] = postid;
|
||||
// Populates the circles combo items
|
||||
|
||||
if (e.AllowedCircles == null)
|
||||
e.AllowedCircles = new long[0];
|
||||
|
||||
ViewData ["AllowedCircles"] =
|
||||
CircleManager.DefaultProvider.List (
|
||||
Membership.GetUser ().UserName).Select (x => new SelectListItem {
|
||||
Value = x.Id.ToString(),
|
||||
Text = x.Title,
|
||||
Selected = e.AllowedCircles.Contains (x.Id)
|
||||
});
|
||||
return View (e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Comment the specified model.
|
||||
/// </summary>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize]
|
||||
public ActionResult Comment (Comment model)
|
||||
{
|
||||
string username = Membership.GetUser ().UserName;
|
||||
ViewData ["SiteName"] = sitename;
|
||||
if (ModelState.IsValid) {
|
||||
BlogManager.Comment (username, model.PostId, model.CommentText, model.Visible);
|
||||
return GetPost (model.PostId);
|
||||
}
|
||||
return GetPost (model.PostId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the specified blog entry, by its author and title,
|
||||
/// using returnUrl as the URL to return to,
|
||||
/// and confirm as a proof you really know what you do.
|
||||
/// </summary>
|
||||
/// <param name="id">Title.</param>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
/// <param name="confirm">If set to <c>true</c> confirm.</param>
|
||||
[Authorize(Roles="Blogger")]
|
||||
public ActionResult RemoveTitle (string user, string title, string returnUrl, bool confirm = false)
|
||||
{
|
||||
if (returnUrl == null)
|
||||
if (Request.UrlReferrer != null)
|
||||
returnUrl = Request.UrlReferrer.AbsoluteUri;
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
ViewData ["Author"] = user;
|
||||
ViewData ["Title"] = title;
|
||||
|
||||
if (Membership.GetUser ().UserName != user)
|
||||
if (!Roles.IsUserInRole("Admin"))
|
||||
throw new AuthorizationDenied (user);
|
||||
if (!confirm)
|
||||
return View ("RemoveTitle");
|
||||
BlogManager.RemoveTitle (user, title);
|
||||
if (returnUrl == null)
|
||||
RedirectToAction ("Index", new { user = user });
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the post.
|
||||
/// </summary>
|
||||
/// <returns>The post.</returns>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
/// <param name="confirm">If set to <c>true</c> confirm.</param>
|
||||
[Authorize(Roles="Blogger")]
|
||||
public ActionResult RemovePost (long postid, string returnUrl, bool confirm = false)
|
||||
{
|
||||
// ensures the access control
|
||||
BlogEntry e = BlogManager.GetForEditing (postid);
|
||||
if (e == null)
|
||||
return new HttpNotFoundResult ("post id "+postid.ToString());
|
||||
ViewData ["id"] = postid;
|
||||
ViewData ["returnUrl"] = string.IsNullOrWhiteSpace(returnUrl)?
|
||||
Request.UrlReferrer.AbsoluteUri.ToString(): returnUrl;
|
||||
// TODO: cleaner way to disallow deletion
|
||||
if (!confirm)
|
||||
return View ("RemovePost",e);
|
||||
BlogManager.RemovePost (postid);
|
||||
if (string.IsNullOrWhiteSpace(returnUrl))
|
||||
return RedirectToAction ("Index");
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
67
booking/Controllers/FileSystemController.cs
Normal file
67
booking/Controllers/FileSystemController.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.IO;
|
||||
using System.Web.Security;
|
||||
using System.Text.RegularExpressions;
|
||||
using Yavsc.Model.FileSystem;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// File system controller.
|
||||
/// </summary>
|
||||
|
||||
public class FileSystemController : Controller
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the specified requestContext.
|
||||
/// </summary>
|
||||
/// <param name="requestContext">Request context.</param>
|
||||
[Authorize]
|
||||
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||
{
|
||||
base.Initialize (requestContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public ActionResult Index (string user, string filename)
|
||||
{
|
||||
WebFileSystemManager fsmgr = new WebFileSystemManager ();
|
||||
var files = fsmgr.GetFiles (user,filename);
|
||||
return View (files);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Post the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult Post (string id)
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Details the specified user and filename.
|
||||
/// </summary>
|
||||
/// <param name="user">User.</param>
|
||||
/// <param name="filename">Filename.</param>
|
||||
public ActionResult Details (string user, string filename)
|
||||
{
|
||||
WebFileSystemManager fsmgr = new WebFileSystemManager ();
|
||||
FileInfo fi = fsmgr.FileInfo (filename);
|
||||
|
||||
ViewData ["filename"] = filename;
|
||||
// TODO : ensure that we use the default port for
|
||||
// the used sheme
|
||||
ViewData ["url"] = Url.Content("~/users/"+user+"/"+filename);
|
||||
return View (fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
263
booking/Controllers/FrontOfficeController.cs
Normal file
263
booking/Controllers/FrontOfficeController.cs
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
using System;
|
||||
using Yavsc;
|
||||
using System.Web.Mvc;
|
||||
using System.Web;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using Yavsc.Controllers;
|
||||
using System.Collections.Generic;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Model.WorkFlow;
|
||||
using System.Web.Security;
|
||||
using System.Threading;
|
||||
using Yavsc.Model.FrontOffice;
|
||||
using Yavsc.Model.FileSystem;
|
||||
using Yavsc.Model.Calendar;
|
||||
using System.Configuration;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Model.FrontOffice.Catalog;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Front office controller.
|
||||
/// Access granted to all
|
||||
/// </summary>
|
||||
public class FrontOfficeController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// The wfmgr.
|
||||
/// </summary>
|
||||
protected WorkFlowManager wfmgr = null;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the specified requestContext.
|
||||
/// </summary>
|
||||
/// <param name="requestContext">Request context.</param>
|
||||
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||
{
|
||||
base.Initialize (requestContext);
|
||||
wfmgr = new WorkFlowManager ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Pub the Event
|
||||
/// </summary>
|
||||
/// <returns>The pub.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
public ActionResult EventPub (EventPub model)
|
||||
{
|
||||
return View (model);
|
||||
}
|
||||
/// <summary>
|
||||
/// Estimates this instance.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public ActionResult Estimates (string client)
|
||||
{
|
||||
var u = Membership.GetUser ();
|
||||
if (u == null) // There was no redirection to any login page
|
||||
throw new ConfigurationErrorsException ("no redirection to any login page");
|
||||
|
||||
string username = u.UserName;
|
||||
Estimate [] estims = wfmgr.GetUserEstimates (username);
|
||||
ViewData ["UserName"] = username;
|
||||
ViewData ["ResponsibleCount"] =
|
||||
Array.FindAll (
|
||||
estims,
|
||||
x => x.Responsible == username).Length;
|
||||
ViewData ["ClientCount"] =
|
||||
Array.FindAll (
|
||||
estims,
|
||||
x => x.Client == username).Length;
|
||||
return View (estims);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Estimate the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
public ActionResult Get (long id)
|
||||
{
|
||||
Estimate f = wfmgr.GetEstimate (id);
|
||||
if (f == null) {
|
||||
ModelState.AddModelError ("Id", "Wrong Id");
|
||||
return View (new Estimate () { Id=id } );
|
||||
}
|
||||
return View (f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Estimate the specified model and submit.
|
||||
/// </summary>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="submit">Submit.</param>
|
||||
[Authorize]
|
||||
public ActionResult Estimate (Estimate model, string submit)
|
||||
{
|
||||
string username = Membership.GetUser().UserName;
|
||||
// Obsolete, set in master page
|
||||
ViewData ["WebApiBase"] = Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative);
|
||||
ViewData ["WABASEWF"] = ViewData ["WebApiBase"] + "/WorkFlow";
|
||||
if (submit == null) {
|
||||
if (model.Id > 0) {
|
||||
Estimate f = wfmgr.GetEstimate (model.Id);
|
||||
if (f == null) {
|
||||
ModelState.AddModelError ("Id", "Wrong Id");
|
||||
return View (model);
|
||||
}
|
||||
model = f;
|
||||
ModelState.Clear ();
|
||||
if (username != model.Responsible
|
||||
&& username != model.Client
|
||||
&& !Roles.IsUserInRole ("FrontOffice"))
|
||||
throw new UnauthorizedAccessException ("You're not allowed to view this estimate");
|
||||
} else if (model.Id == 0) {
|
||||
if (string.IsNullOrWhiteSpace(model.Responsible))
|
||||
model.Responsible = username;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (model.Id == 0) // if (submit == "Create")
|
||||
if (string.IsNullOrWhiteSpace (model.Responsible))
|
||||
model.Responsible = username;
|
||||
if (username != model.Responsible
|
||||
&& !Roles.IsUserInRole ("FrontOffice"))
|
||||
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate");
|
||||
|
||||
if (ModelState.IsValid) {
|
||||
if (model.Id == 0)
|
||||
model = wfmgr.CreateEstimate (
|
||||
username,
|
||||
model.Client, model.Title, model.Description);
|
||||
else {
|
||||
wfmgr.UpdateEstimate (model);
|
||||
model = wfmgr.GetEstimate (model.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Catalog this instance.
|
||||
/// </summary>
|
||||
[AcceptVerbs ("GET")]
|
||||
public ActionResult Catalog ()
|
||||
{
|
||||
return View (
|
||||
CatalogManager.GetCatalog ()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Catalog this instance.
|
||||
/// </summary>
|
||||
[AcceptVerbs ("GET")]
|
||||
public ActionResult Brand (string id)
|
||||
{
|
||||
Catalog c = CatalogManager.GetCatalog ();
|
||||
ViewData ["BrandName"] = id;
|
||||
return View (c.GetBrand (id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get the product category
|
||||
/// </summary>
|
||||
/// <returns>The category object.</returns>
|
||||
/// <param name="brandid">Brand id.</param>
|
||||
/// <param name="pcid">Product category Id.</param>
|
||||
[AcceptVerbs ("GET")]
|
||||
public ActionResult ProductCategory (string brandid, string pcid)
|
||||
{
|
||||
ViewData ["BrandId"] = brandid;
|
||||
ViewData ["ProductCategoryId"] = pcid;
|
||||
|
||||
var cat = CatalogManager.GetCatalog ();
|
||||
if (cat == null)
|
||||
throw new Exception ("No catalog");
|
||||
var brand = cat.GetBrand (brandid);
|
||||
if (brand == null)
|
||||
throw new Exception ("Not a brand id: "+brandid);
|
||||
var pcat = brand.GetProductCategory (pcid);
|
||||
if (pcat == null)
|
||||
throw new Exception ("Not a product category id in this brand: " + pcid);
|
||||
return View (pcat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Product the specified id, pc and pref.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier.</param>
|
||||
/// <param name="pc">Pc.</param>
|
||||
/// <param name="pref">Preference.</param>
|
||||
[AcceptVerbs ("GET")]
|
||||
public ActionResult Product (string id, string pc, string pref)
|
||||
{
|
||||
Product p = null;
|
||||
ViewData ["BrandName"] = id;
|
||||
ViewData ["ProdCatRef"] = pc;
|
||||
ViewData ["ProdRef"] = pref;
|
||||
Catalog cat = CatalogManager.GetCatalog ();
|
||||
if (cat == null) {
|
||||
YavscHelpers.Notify(ViewData, "Catalog introuvable");
|
||||
ViewData ["RefType"] = "Catalog";
|
||||
return View ("ReferenceNotFound");
|
||||
}
|
||||
Brand b = cat.GetBrand (id);
|
||||
if (b == null) {
|
||||
ViewData ["RefType"] = "Brand";
|
||||
return View ("ReferenceNotFound");
|
||||
}
|
||||
ProductCategory pcat = b.GetProductCategory (pc);
|
||||
if (pcat == null) {
|
||||
ViewData ["RefType"] = "ProductCategory";
|
||||
return View ("ReferenceNotFound");
|
||||
}
|
||||
ViewData ["ProdCatName"] = pcat.Name;
|
||||
p = pcat.GetProduct (pref);
|
||||
if (p.CommandForm == null)
|
||||
p.CommandForm = b.DefaultForm;
|
||||
|
||||
return View ((p is Service) ? "Service" : "Product", p);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basket this instance.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public ActionResult Basket ()
|
||||
{
|
||||
return View (wfmgr.GetCommands (Membership.GetUser ().UserName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Command the specified collection.
|
||||
/// </summary>
|
||||
/// <param name="collection">Collection.</param>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult Command (FormCollection collection)
|
||||
{
|
||||
try {
|
||||
// Add specified product command to the basket,
|
||||
// saves it in db
|
||||
new Command(collection,HttpContext.Request.Files);
|
||||
YavscHelpers.Notify(ViewData, LocalizedText.Item_added_to_basket);
|
||||
return View (collection);
|
||||
} catch (Exception e) {
|
||||
YavscHelpers.Notify(ViewData,"Exception:" + e.Message);
|
||||
return View (collection);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
367
booking/Controllers/GoogleController.cs
Normal file
367
booking/Controllers/GoogleController.cs
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Profile;
|
||||
using System.Web.Security;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Model.Google;
|
||||
using Yavsc.Model.RolesAndMembers;
|
||||
using Yavsc.Helpers.Google;
|
||||
using Yavsc.Model.Calendar;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Google controller.
|
||||
/// </summary>
|
||||
public class GoogleController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
private string SetSessionSate ()
|
||||
{
|
||||
string state = "security_token";
|
||||
Random rand = new Random ();
|
||||
for (int l = 0; l < 32; l++) {
|
||||
int r = rand.Next (62);
|
||||
char c;
|
||||
if (r < 10) {
|
||||
c = (char)('0' + r);
|
||||
} else if (r < 36) {
|
||||
r -= 10;
|
||||
c = (char) ('a' + r);
|
||||
} else {
|
||||
r -= 36;
|
||||
c = (char) ('A' + r);
|
||||
}
|
||||
state += c;
|
||||
}
|
||||
Session ["state"] = state;
|
||||
return state;
|
||||
}
|
||||
|
||||
private string AuthGRU {
|
||||
get {
|
||||
return Request.Url.Scheme + "://" +
|
||||
Request.Url.Authority + "/Google/Auth";
|
||||
}
|
||||
}
|
||||
|
||||
private string CalendarGRU {
|
||||
get {
|
||||
return Request.Url.Scheme + "://" +
|
||||
Request.Url.Authority + "/Google/CalAuth";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Login the specified returnUrl.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
public void Login (string returnUrl)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace (returnUrl))
|
||||
returnUrl = "/";
|
||||
Session ["returnUrl"] = returnUrl;
|
||||
OAuth2 oa = new OAuth2 (AuthGRU,clientId,clientSecret);
|
||||
oa.Login (Response, SetSessionSate ());
|
||||
}
|
||||
private string clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"];
|
||||
private string clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"];
|
||||
private string clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"];
|
||||
/// <summary>
|
||||
/// Gets the cal auth.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
public void GetCalAuth (string returnUrl)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace (returnUrl))
|
||||
returnUrl = "/";
|
||||
Session ["returnUrl"] = returnUrl;
|
||||
OAuth2 oa = new OAuth2 (CalendarGRU,clientId,clientSecret);
|
||||
oa.GetCalendarScope (Response, SetSessionSate ());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the Google authorizations screen,
|
||||
/// we assume that <c>Session</c> contains a redirectUrl entry
|
||||
/// </summary>
|
||||
/// <returns>The auth.</returns>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public ActionResult CalAuth ()
|
||||
{
|
||||
string msg;
|
||||
OAuth2 oa = new OAuth2 (CalendarGRU,clientId,clientSecret);
|
||||
|
||||
AuthToken gat = oa.GetToken (Request, (string) Session ["state"], out msg);
|
||||
if (gat == null) {
|
||||
YavscHelpers.Notify(ViewData, msg);
|
||||
return View ("Auth");
|
||||
}
|
||||
SaveToken (HttpContext.Profile,gat);
|
||||
HttpContext.Profile.SetPropertyValue ("gcalapi", true);
|
||||
string returnUrl = (string) Session ["returnUrl"];
|
||||
Session ["returnUrl"] = null;
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the token.
|
||||
/// This calls the Profile.Save() method.
|
||||
/// It should be called immediatly after getting the token from Google, in
|
||||
/// order to save a descent value as expiration date.
|
||||
/// </summary>
|
||||
/// <param name="gat">Gat.</param>
|
||||
private void SaveToken (ProfileBase pr, AuthToken gat)
|
||||
{
|
||||
pr.SetPropertyValue ("gtoken", gat.access_token);
|
||||
if (gat.refresh_token != null)
|
||||
pr.SetPropertyValue ("grefreshtoken", gat.refresh_token);
|
||||
pr.SetPropertyValue ("gtokentype", gat.token_type);
|
||||
pr.SetPropertyValue ("gtokenexpir", DateTime.Now.AddSeconds (gat.expires_in));
|
||||
pr.Save ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auth this instance.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public ActionResult Auth ()
|
||||
{
|
||||
string msg;
|
||||
OAuth2 oa = new OAuth2 (AuthGRU,clientId,clientSecret);
|
||||
AuthToken gat = oa.GetToken (Request, (string)Session ["state"], out msg);
|
||||
if (gat == null) {
|
||||
YavscHelpers.Notify(ViewData, msg);
|
||||
return View ();
|
||||
}
|
||||
string returnUrl = (string)Session ["returnUrl"];
|
||||
SignIn regmod = new SignIn ();
|
||||
|
||||
People me = PeopleApi.GetMe (gat);
|
||||
// TODO use me.id to retreive an existing user
|
||||
string accEmail = me.emails.Where (x => x.type == "account").First ().value;
|
||||
MembershipUserCollection mbrs = Membership.FindUsersByEmail (accEmail);
|
||||
if (mbrs.Count == 1) {
|
||||
// TODO check the google id
|
||||
// just set this user as logged on
|
||||
foreach (MembershipUser u in mbrs) {
|
||||
string username = u.UserName;
|
||||
FormsAuthentication.SetAuthCookie (username, true);
|
||||
/* var upr = ProfileBase.Create (username);
|
||||
SaveToken (upr,gat); */
|
||||
}
|
||||
Session ["returnUrl"] = null;
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
// else create the account
|
||||
regmod.Email = accEmail;
|
||||
regmod.UserName = me.displayName;
|
||||
Session ["me"] = me;
|
||||
Session ["GoogleAuthToken"] = gat;
|
||||
return Auth (regmod);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an account using the Google authentification.
|
||||
/// </summary>
|
||||
/// <param name="regmod">Regmod.</param>
|
||||
[HttpPost]
|
||||
public ActionResult Auth (SignIn regmod)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
if (Membership.GetUser (regmod.UserName) != null) {
|
||||
ModelState.AddModelError ("UserName", "This user name already is in use");
|
||||
return View ();
|
||||
}
|
||||
string returnUrl = (string) Session ["returnUrl"];
|
||||
AuthToken gat = (AuthToken) Session ["GoogleAuthToken"];
|
||||
People me = (People)Session ["me"];
|
||||
if (gat == null || me == null)
|
||||
throw new InvalidDataException ();
|
||||
|
||||
Random rand = new Random ();
|
||||
string passwd = rand.Next (100000).ToString () + rand.Next (100000).ToString ();
|
||||
|
||||
MembershipCreateStatus mcs;
|
||||
Membership.CreateUser (
|
||||
regmod.UserName,
|
||||
passwd,
|
||||
regmod.Email,
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
out mcs);
|
||||
switch (mcs) {
|
||||
case MembershipCreateStatus.DuplicateEmail:
|
||||
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||
"à un compte utilisateur existant");
|
||||
return View (regmod);
|
||||
case MembershipCreateStatus.DuplicateUserName:
|
||||
ModelState.AddModelError ("UserName", "Ce nom d'utilisateur est " +
|
||||
"déjà enregistré");
|
||||
return View (regmod);
|
||||
case MembershipCreateStatus.Success:
|
||||
Membership.ValidateUser (regmod.UserName, passwd);
|
||||
FormsAuthentication.SetAuthCookie (regmod.UserName, true);
|
||||
|
||||
HttpContext.Profile.Initialize (regmod.UserName, true);
|
||||
HttpContext.Profile.SetPropertyValue ("Name", me.displayName);
|
||||
// TODO use image
|
||||
if (me.image != null) {
|
||||
HttpContext.Profile.SetPropertyValue ("Avatar", me.image.url);
|
||||
}
|
||||
if (me.placesLived != null) {
|
||||
People.Place pplace = me.placesLived.Where (x => x.primary).First ();
|
||||
if (pplace != null)
|
||||
HttpContext.Profile.SetPropertyValue ("CityAndState", pplace.value);
|
||||
}
|
||||
if (me.url != null)
|
||||
HttpContext.Profile.SetPropertyValue ("WebSite", me.url);
|
||||
// Will be done in SaveToken: HttpContext.Profile.Save ();
|
||||
SaveToken (HttpContext.Profile, gat);
|
||||
Session ["returnUrl"] = null;
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
ViewData ["returnUrl"] = returnUrl;
|
||||
}
|
||||
return View (regmod);
|
||||
}
|
||||
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
ActionResult PushPos ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chooses the calendar.
|
||||
/// </summary>
|
||||
/// <returns>The calendar.</returns>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public ActionResult ChooseCalendar (string returnUrl)
|
||||
{
|
||||
if (returnUrl != null) {
|
||||
Session ["chooseCalReturnUrl"] = returnUrl;
|
||||
return RedirectToAction ("GetCalAuth",
|
||||
new {
|
||||
returnUrl = Url.Action ("ChooseCalendar") // "ChooseCalendar?returnUrl="+HttpUtility.UrlEncode(returnUrl)
|
||||
});
|
||||
}
|
||||
string cred = OAuth2.GetFreshGoogleCredential (HttpContext.Profile);
|
||||
CalendarApi c = new CalendarApi (clientApiKey);
|
||||
CalendarList cl = c.GetCalendars (cred);
|
||||
ViewData ["returnUrl"] = Session ["chooseCalReturnUrl"];
|
||||
return View (cl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the calendar.
|
||||
/// </summary>
|
||||
/// <returns>The calendar.</returns>
|
||||
/// <param name="calchoice">Calchoice.</param>
|
||||
/// <param name="returnUrl">return Url.</param>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult SetCalendar (string calchoice,string returnUrl)
|
||||
{
|
||||
HttpContext.Profile.SetPropertyValue ("gcalid", calchoice);
|
||||
HttpContext.Profile.Save ();
|
||||
|
||||
if (returnUrl != null) {
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
return Redirect ("/");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dates the query.
|
||||
/// </summary>
|
||||
/// <returns>The query.</returns>
|
||||
[Authorize,HttpGet]
|
||||
public ActionResult Book ()
|
||||
{
|
||||
var model = new BookQuery ();
|
||||
model.StartDate = DateTime.Now;
|
||||
model.EndDate = model.StartDate.AddDays(2);
|
||||
model.StartHour = DateTime.Now.ToString("HH:mm");
|
||||
model.EndHour = DateTime.Now.AddHours(1).ToString("HH:mm");
|
||||
return View (model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dates the query.
|
||||
/// </summary>
|
||||
/// <returns>The query.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize,HttpPost]
|
||||
public ActionResult Book (BookQuery model)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
DateTime mindate = DateTime.Now;
|
||||
if (model.StartDate.Date < mindate.Date){
|
||||
ModelState.AddModelError ("StartDate", LocalizedText.FillInAFutureDate);
|
||||
}
|
||||
if (model.EndDate < model.StartDate)
|
||||
ModelState.AddModelError ("EndDate", LocalizedText.StartDateAfterEndDate);
|
||||
|
||||
var muc = Membership.FindUsersByName (model.Person);
|
||||
if (muc.Count == 0) {
|
||||
ModelState.AddModelError ("Person", LocalizedText.Non_existent_user);
|
||||
}
|
||||
if (!Roles.IsUserInRole (model.Role)) {
|
||||
ModelState.AddModelError ("Role", LocalizedText.UserNotInThisRole);
|
||||
}
|
||||
ProfileBase upr = ProfileBase.Create (model.Person);
|
||||
var gcalid = upr.GetPropertyValue ("gcalid");
|
||||
if (gcalid is DBNull)
|
||||
ModelState.AddModelError ("Person", LocalizedText.No_calendar_for_this_user);
|
||||
if (ModelState.IsValid) {
|
||||
string calid = (string) gcalid;
|
||||
DateTime maxdate = model.EndDate;
|
||||
CalendarApi c = new CalendarApi (clientApiKey);
|
||||
CalendarEventList events;
|
||||
try {
|
||||
string creds = OAuth2.GetFreshGoogleCredential (upr);
|
||||
events = c.GetCalendar (calid, mindate, maxdate, creds);
|
||||
YavscHelpers.Notify (ViewData, "Google calendar API call success");
|
||||
} catch (WebException ex) {
|
||||
string response;
|
||||
using (var stream = ex.Response.GetResponseStream())
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
response = reader.ReadToEnd();
|
||||
}
|
||||
YavscHelpers.Notify (ViewData,
|
||||
string.Format(
|
||||
"Google calendar API exception {0} : {1}<br><pre>{2}</pre>",
|
||||
ex.Status.ToString(),
|
||||
ex.Message,
|
||||
response));
|
||||
}
|
||||
}
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
}
|
||||
}
|
||||
138
booking/Controllers/HomeController.cs
Normal file
138
booking/Controllers/HomeController.cs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using Yavsc.Model;
|
||||
using Npgsql.Web;
|
||||
using Npgsql.Web.Blog;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Model.Blogs;
|
||||
using System.Web.Security;
|
||||
using System.Web.Profile;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Home controller.
|
||||
/// </summary>
|
||||
public class HomeController : Controller
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Lists the referenced assemblies.
|
||||
/// </summary>
|
||||
/// <returns>The info.</returns>
|
||||
public ActionResult AssemblyInfo()
|
||||
{
|
||||
Assembly[] aslist = {
|
||||
GetType ().Assembly,
|
||||
typeof(ITCPNpgsqlProvider).Assembly,
|
||||
typeof(NpgsqlMembershipProvider).Assembly,
|
||||
typeof(NpgsqlContentProvider).Assembly,
|
||||
typeof(NpgsqlBlogProvider).Assembly
|
||||
};
|
||||
|
||||
List <AssemblyName> asnlist = new List<AssemblyName> ();
|
||||
foreach (Assembly asse in aslist) {
|
||||
foreach (AssemblyName an in asse.GetReferencedAssemblies ()) {
|
||||
if (asnlist.All(x=> string.Compare(x.Name,an.Name)!=0))
|
||||
asnlist.Add (an);
|
||||
}
|
||||
}
|
||||
asnlist.Sort (delegate(AssemblyName x, AssemblyName y) {
|
||||
return string.Compare (x.Name, y.Name);
|
||||
});
|
||||
return View (asnlist.ToArray()) ;
|
||||
}
|
||||
|
||||
private static string owneremail = null;
|
||||
/// <summary>
|
||||
/// Gets or sets the owner email.
|
||||
/// </summary>
|
||||
/// <value>The owner email.</value>
|
||||
public static string OwnerEmail {
|
||||
get {
|
||||
if (owneremail == null)
|
||||
owneremail = WebConfigurationManager.AppSettings.Get ("OwnerEMail");
|
||||
return owneremail;
|
||||
}
|
||||
set {
|
||||
owneremail = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index ()
|
||||
{
|
||||
if (Session.IsNewSession) {
|
||||
string uid = (!Request.IsAuthenticated) ? Request.AnonymousID : User.Identity.Name;
|
||||
ProfileBase pr =
|
||||
ProfileBase.Create (uid);
|
||||
bool ac = (bool) pr.GetPropertyValue ("allowcookies");
|
||||
if (!ac)
|
||||
YavscHelpers.Notify (ViewData, LocalizedText.ThisSiteUsesCookies,
|
||||
"function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+uid+"' });}",
|
||||
LocalizedText.I_understood);
|
||||
}
|
||||
|
||||
foreach (string tagname in new string[] {"Accueil","Événements","Mentions légales"})
|
||||
{
|
||||
TagInfo ti = BlogManager.GetTagInfo (tagname);
|
||||
// TODO specialyze BlogEntry creating a PhotoEntry
|
||||
ViewData [tagname] = ti;
|
||||
}
|
||||
return View ();
|
||||
}
|
||||
/// <summary>
|
||||
/// Credits this instance.
|
||||
/// </summary>
|
||||
public ActionResult Credits ()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contact the specified email, reason and body.
|
||||
/// </summary>
|
||||
/// <param name="email">Email.</param>
|
||||
/// <param name="reason">Reason.</param>
|
||||
/// <param name="body">Body.</param>
|
||||
public ActionResult Contact (string email, string reason, string body)
|
||||
{
|
||||
if (email==null)
|
||||
ModelState.AddModelError("email","Enter your email");
|
||||
|
||||
if (reason==null)
|
||||
ModelState.AddModelError("reason","Please, fill in a reason");
|
||||
|
||||
if (body==null)
|
||||
ModelState.AddModelError("body","Please, fill in a body");
|
||||
if (!ModelState.IsValid)
|
||||
return View ();
|
||||
|
||||
// requires valid owner and admin email?
|
||||
if (OwnerEmail == null)
|
||||
throw new Exception ("No site owner!");
|
||||
|
||||
using (System.Net.Mail.MailMessage msg = new MailMessage(email,OwnerEmail,"[Contact] "+reason,body))
|
||||
{
|
||||
msg.CC.Add(new MailAddress(YavscHelpers.Admail));
|
||||
using (System.Net.Mail.SmtpClient sc = new SmtpClient())
|
||||
{
|
||||
sc.Send (msg);
|
||||
YavscHelpers.Notify(ViewData, LocalizedText.Message_sent);
|
||||
return View (new { email=email, reason="", body="" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
36
booking/Controllers/ModuleController.cs
Normal file
36
booking/Controllers/ModuleController.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Yavsc.Model;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Module controller.
|
||||
/// </summary>
|
||||
public class ModuleController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize the specified requestContext.
|
||||
/// </summary>
|
||||
/// <param name="requestContext">Request context.</param>
|
||||
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||
{
|
||||
base.Initialize (requestContext);
|
||||
ConfigurationManager.GetSection ("ymodules");
|
||||
|
||||
}
|
||||
|
||||
// List<IModule> modules = new List<IModule> ();
|
||||
/// <summary>
|
||||
/// Index this instance.
|
||||
/// </summary>
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue