/// <summary> /// Gets the user model for the given id. /// </summary> /// <param name="id">The user id</param> /// <returns>The model</returns> public static UserEditModel GetById(Guid id) { UserEditModel m = new UserEditModel(); m.User = SysUser.GetSingle(id); m.Password = SysUserPassword.GetSingle(id); m.Groups = new SelectList(m.groups, "Id", "Name", m.User.GroupId); return(m); }
/// <summary> /// Gets the currently logged in user. /// </summary> /// <param name="p">The security principal</param> /// <returns>The current user</returns> public static SysUser GetProfile(this IPrincipal p) { if (Piranha.Application.Current.UserProvider.IsAuthenticated) { // Reload user if session has been dropped if (HttpContext.Current.Session[USER] == null) HttpContext.Current.Session[USER] = SysUser.GetSingle(Piranha.Application.Current.UserProvider.UserId) ; return (SysUser)HttpContext.Current.Session[USER] ; } return new SysUser() ; }
public ActionResult NewPassword() { string login = Request["login"]; string returl = Request["returnurl"]; string failurl = Request["failureurl"]; var userexists = false; using (var db = new DataContext()) { userexists = db.Users.Where(u => u.Login == login).Count() > 0; } if (userexists) { if (WebPages.Hooks.Mail.SendPassword != null) { using (var db = new DataContext()) { var user = db.Users.Where(u => u.Login == login).Single(); user.GenerateAndSendPassword(db); if (!String.IsNullOrEmpty(returl)) { return(Redirect(returl)); } return(Redirect("~/")); } } else if (WebPages.Hooks.Mail.SendPasswordMail != null) { var pwd = SysUserPassword.GetSingle("sysuser_login = @0", login); var user = SysUser.GetSingle("sysuser_login = @0", login); if (pwd != null) { pwd.Password = SysUserPassword.GeneratePassword(); pwd.Save(); WebPages.Hooks.Mail.SendPasswordMail(user, pwd.Password); if (!String.IsNullOrEmpty(returl)) { return(Redirect(returl)); } return(Redirect("~/")); } } } if (!String.IsNullOrEmpty(failurl)) { return(Redirect(failurl)); } return(Redirect("~/")); }
/// <summary> /// Gets the currently logged in user. /// </summary> /// <param name="p">The security principal</param> /// <returns>The current user</returns> public static SysUser GetProfile(this IPrincipal p) { if (p.Identity.IsAuthenticated) { // Reload user if session has been dropped if (HttpContext.Current.Session[USER] == null) { HttpContext.Current.Session[USER] = SysUser.GetSingle(new Guid(p.Identity.Name)); } return((SysUser)HttpContext.Current.Session[USER]); } return(new SysUser()); }