Created
July 22, 2014 04:25
-
-
Save Connicpu/9aab04f3c9e8a78bee40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public ActionResult UpdatePrefix(ChangePrefixModel model) { | |
if (!Request.IsAuthenticated) return RedirectToAction("Login", "Account"); | |
var referer = Request.UrlReferrer ?? new Uri("/"); | |
if (User.Identity.Name != model.User && !CmcsRoleProvider.IsStaff(User.Identity.Name)) { | |
return Redirect(referer.ToString()); | |
} | |
if (!ModelState.IsValid) | |
return Redirect(referer.ToString()); | |
var user = database.permissions_entity.FirstOrDefault(entity => entity.type && entity.name == model.User); | |
if (user == null) return Redirect(referer.ToString()); | |
if (string.IsNullOrWhiteSpace(model.Prefix)) { | |
user.prefix = ""; | |
UpdateEntity(user); | |
RemoteConsole.Command("/pex reload"); | |
return Redirect(referer.ToString()); | |
} | |
var userParents = Roles.GetRolesForUser(user.name); | |
if (userParents.Length < 1) return Redirect(referer.ToString()); | |
var mainParentName = userParents.Last(); | |
var mainParent = database. | |
permissions_entity.FirstOrDefault(entity => !entity.type && entity.name == mainParentName); | |
if (mainParent == null) return Redirect(referer.ToString()); | |
user.prefix = "&" + (char)model.Color + "[" + model.Prefix + "]" + mainParent.prefix; | |
UpdateEntity(user); | |
RemoteConsole.Command("/pex reload"); | |
return Redirect(referer.ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment