public void UpdateUser(User user) { if (user == null) throw new ArgumentNullException("user"); _useRepository.Update(user); //还触发了事件通知! //_eventPublisher.EntityUpdated(customer); }
public void InsertUser(User user) { if (user == null) throw new ArgumentNullException("user"); _useRepository.Insert(user); //event notification //_eventPublisher.EntityInserted(customer); }
public UserRegistrationRequest(User user, string email,string mobile, string username, string password, PasswordFormat passwordFormat, bool isApproved = true) { this.User = user; this.Email = email; this.Username = username; this.Password = password; this.PasswordFormat = passwordFormat; this.IsApproved = isApproved; Mobile = mobile; }
public void DeleteUser(User user) { if(user==null) throw new ArgumentNullException("user"); if(user.IsSystemAccount) throw new PortalException(string.Format("系统用户{0}不能删除",user.SystemName)); user.Deleted = true; if (!String.IsNullOrEmpty(user.Email)) user.Email += "-DELETED"; if (!String.IsNullOrEmpty(user.Username)) user.Username += "-DELETED"; UpdateUser(user); }
public ActionResult Create(RegisterModel model) { ViewBag.Des = "新增操作员"; var roles = _service.GetAllUserRoles().TakeWhile(n => n.SystemName != SystemUserRoleNames.Administrators); ViewBag.Roles = new SelectList(roles, "Id", "Name"); User newuser; if (model.Id == 0) { var user = new User { UserGuid = Guid.NewGuid(), Username = model.UserName, Email = model.Email, Mobile = model.Mobile, Active = true, //加密存储 Password = Encrypt.EncryptString(model.Password), }; //默认增加注册角色 // 先插入 _service.InsertUser(user); newuser = _service.GetUserByUsername(user.Username); } else { newuser = _service.GetUserById(model.Id); newuser.Username = model.UserName; newuser.Password = Encrypt.EncryptString(model.Password); newuser.Email = model.Email; newuser.Mobile = model.Mobile; ViewBag.Des = "编辑用户"; } var role = _service.GetUserRoleById(model.RoleId); //先只有一个角色 newuser.UserRoles.Clear(); newuser.UserRoles.Add(role); try { _service.UpdateUser(newuser); Success(); model.Empty(); } catch (Exception e) { Error(e.Message); } return View(model); }
public User GetAuthenticatedCustomer() { if (_cachedUser != null) return _cachedUser; if (HttpContext == null || HttpContext.Request == null || !HttpContext.Request.IsAuthenticated || !(HttpContext.User.Identity is FormsIdentity)) { return null; } var formsIdentity = (FormsIdentity)HttpContext.User.Identity; var user = GetAuthenticatedUserFromTicket(formsIdentity.Ticket); if (user != null && user.Active && !user.Deleted )//&& user.IsRegistered() _cachedUser = user; return _cachedUser; }
public void SetUsername(User user, string newUsername) { if (user == null) throw new ArgumentNullException("user"); newUsername = newUsername.Trim(); if (newUsername.Length > 100) throw new PortalException("用户名太长"); var user2 = _userService.GetUserByUsername(newUsername); if (user2 != null && user.Id != user2.Id) throw new PortalException("用户名已经存在"); user.Username = newUsername; _userService.UpdateUser(user); }
public void SignIn(User user, bool createPersistentCookie) { var now = DateTime.UtcNow.ToLocalTime(); var ticket = new FormsAuthenticationTicket(1, user.Username, now, now.Add(_expirationTimeSpan), createPersistentCookie, user.Username, FormsAuthentication.FormsCookiePath); var encryptedTicket = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) {HttpOnly = true}; if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } cookie.Secure = FormsAuthentication.RequireSSL; cookie.Path = FormsAuthentication.FormsCookiePath; if (FormsAuthentication.CookieDomain != null) { cookie.Domain = FormsAuthentication.CookieDomain; } HttpContext.Response.Cookies.Add(cookie); //nop源码中没有这一句,务必保证webconfig中的认证是form的。 // FormsAuthentication.SetAuthCookie(user.Username, createPersistentCookie); _cachedUser = user; }
public void SetEmail(User user, string newEmail) { }
public bool Authorize(string permissionRecordSystemName, User user) { if (String.IsNullOrEmpty(permissionRecordSystemName)) return false; var customerRoles = user.UserRoles.Where(cr => cr.Active); foreach (var role in customerRoles) if (Authorize(permissionRecordSystemName, role)) return true; //no permission found return false; }
public bool Authorize(PermissionRecord permission, User user) { if (permission == null) return false; if (user == null) return false; return Authorize(permission.SystemName, user); }
public RegisterModel(User user) { if (user != null) { Id = user.Id; UserName = user.Username; Mobile = user.Mobile; Password = ""; Email = user.Email; if (user.UserRoles.Any()) { RoleId = user.UserRoles.FirstOrDefault().Id; } } }
public void SignOut() { _cachedUser = null; FormsAuthentication.SignOut(); }
public virtual User InsertGuestUser() { var customer = new User { UserGuid = Guid.NewGuid(), Active = true, LastActivityDateUtc = DateTime.UtcNow, }; //add to 'Guests' role //var guestRole = GetUserRoleBySystemName(SystemUserRoleNames.Guests); //if (guestRole == null) // throw new PortalException("'Guests' role could not be loaded"); //customer.UserRoles.Add(guestRole); // _useRepository.Insert(customer); return customer; }