|
|
|
@ -100,11 +100,16 @@ namespace Yavsc.Controllers
|
|
|
|
|
return View (model);
|
|
|
|
|
case MembershipCreateStatus.Success:
|
|
|
|
|
FileInfo fi = new FileInfo (
|
|
|
|
|
Server.MapPath(registrationMessage));
|
|
|
|
|
Server.MapPath (registrationMessage));
|
|
|
|
|
if (!fi.Exists) {
|
|
|
|
|
ViewData["Error"] = "Erreur inattendue (pas de corps de message à envoyer)";
|
|
|
|
|
ViewData ["Error"] =
|
|
|
|
|
string.Format (
|
|
|
|
|
"Erreur inattendue (pas de corps de message " +
|
|
|
|
|
"à envoyer pour le message de confirmation ({0}))",
|
|
|
|
|
registrationMessage);
|
|
|
|
|
return View (model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (StreamReader sr = fi.OpenText()) {
|
|
|
|
|
string body = sr.ReadToEnd();
|
|
|
|
|
body = body.Replace("<%SiteName%>",YavscHelpers.SiteName);
|
|
|
|
@ -189,79 +194,8 @@ namespace Yavsc.Controllers
|
|
|
|
|
return View (model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize()]
|
|
|
|
|
public ActionResult UserList ()
|
|
|
|
|
{
|
|
|
|
|
MembershipUserCollection c = Membership.GetAllUsers ();
|
|
|
|
|
return View (c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const string adminRoleName = "Admin";
|
|
|
|
|
|
|
|
|
|
[Authorize()]
|
|
|
|
|
public ActionResult Admin (NewAdminModel model)
|
|
|
|
|
{
|
|
|
|
|
string currentUser = Membership.GetUser ().UserName;
|
|
|
|
|
if (ModelState.IsValid) {
|
|
|
|
|
Roles.AddUserToRole (model.UserName, adminRoleName);
|
|
|
|
|
ViewData ["Message"] = model.UserName + " was added to the role '" + adminRoleName + "'";
|
|
|
|
|
} else {
|
|
|
|
|
if (!Roles.RoleExists (adminRoleName)) {
|
|
|
|
|
Roles.CreateRole (adminRoleName);
|
|
|
|
|
string.Format ("The role '{0}' has just been created. ",
|
|
|
|
|
adminRoleName);
|
|
|
|
|
}
|
|
|
|
|
string [] admins = Roles.GetUsersInRole (adminRoleName);
|
|
|
|
|
if (admins.Length > 0) {
|
|
|
|
|
if (! admins.Contains (Membership.GetUser ().UserName)) {
|
|
|
|
|
ModelState.Remove("UserName");
|
|
|
|
|
ModelState.AddModelError("UserName", "You're not administrator!");
|
|
|
|
|
return View ("Index");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Roles.AddUserToRole (currentUser, adminRoleName);
|
|
|
|
|
admins = new string[] { currentUser };
|
|
|
|
|
ViewData ["Message"] += string.Format (
|
|
|
|
|
"There was no user in the 'Admin' role. You ({0}) was just added as the firt user in the 'Admin' role. ", currentUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 ["useritems"] = users;
|
|
|
|
|
ViewData ["admins"] = admins;
|
|
|
|
|
}
|
|
|
|
|
return View (model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize()]
|
|
|
|
|
public ActionResult RoleList ()
|
|
|
|
|
{
|
|
|
|
|
return View (Roles.GetAllRoles ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)
|
|
|
|
|
{
|
|
|
|
|
Roles.RemoveUserFromRole(username,rolename);
|
|
|
|
|
return Redirect(returnUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult RemoveUser (string username, string submitbutton)
|
|
|
|
|
{
|
|
|
|
|
if (submitbutton == "Supprimer") {
|
|
|
|
|
Membership.DeleteUser (username);
|
|
|
|
|
ViewData["Message"]=
|
|
|
|
|
string.Format("utilisateur \"{0}\" supprimé",username);
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("UserList");
|
|
|
|
|
}
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
//public ActionResult UpdateProfile(HttpPostedFileBase Avatar, string Address, string CityAndState, string ZipCode, string Country, string WebSite)
|
|
|
|
@ -304,30 +238,6 @@ namespace Yavsc.Controllers
|
|
|
|
|
return RedirectToAction ("Profile");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult RemoveRole (string rolename, string submitbutton)
|
|
|
|
|
{
|
|
|
|
|
if (submitbutton == "Supprimer")
|
|
|
|
|
{
|
|
|
|
|
Roles.DeleteRole(rolename);
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("RoleList");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult RemoveRoleQuery(string rolename)
|
|
|
|
|
{
|
|
|
|
|
ViewData["roletoremove"] = rolename;
|
|
|
|
|
return View ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult RemoveUserQuery(string username)
|
|
|
|
|
{
|
|
|
|
|
ViewData["usertoremove"] = username;
|
|
|
|
|
return UserList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
public ActionResult Logout (string returnUrl)
|
|
|
|
|
{
|
|
|
|
@ -335,20 +245,9 @@ namespace Yavsc.Controllers
|
|
|
|
|
return Redirect(returnUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult AddRole ()
|
|
|
|
|
{
|
|
|
|
|
return View ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles="Admin")]
|
|
|
|
|
public ActionResult DoAddRole (string rolename)
|
|
|
|
|
{
|
|
|
|
|
Roles.CreateRole(rolename);
|
|
|
|
|
ViewData["Message"] = "Rôle créé : "+rolename;
|
|
|
|
|
return View ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ActionResult Validate (string id, string key)
|
|
|
|
|
{
|
|
|
|
|
MembershipUser u = Membership.GetUser (id, false);
|
|
|
|
|