public ActionResult Update(int id, MemberUpdateViewModel model) { var user = _memberService.GetUser(id); if (ModelState.IsValid.Equals(false)) { model.Pic = user.Pic; return(View(model)); } // Update Table Password var newPassword = model.Password; if (string.IsNullOrEmpty(newPassword).Equals(false)) { var newPassEntity = _memberService.ConvertToPassEntity(user.Id, user.Guid, newPassword); // 管理者可以強制變更密碼 if (SignInUser.User.IsAdmin.Equals(false)) { var isSamePassword = _memberService.CheckIsHistroyPassword(user.Id, newPassEntity.HashPw); if (isSamePassword) { ModelState.AddModelError("HistroyPassword", "新密碼不可跟使用過的舊密碼相同。"); model.Password = string.Empty; return(View(model)); } } _memberService.CreatePassword(newPassEntity); } // 大頭照 var fileName = _memberService.SaveMemberPic(model.File, Server.MapPath(FileUploadPath)); if (string.IsNullOrEmpty(fileName).Equals(false)) { user.Pic = $"{FileUploadPath}/{fileName}"; } // Update Table User user.Name = model.Name; _memberService.UpdateUser(user); // 修改自己的資料完畢之後也要更新Session if (SignInUser.User.Id == id) { var artCnt = _memberService.GetUserArticleCount(user.Id); SignInUser.UserLogin(true, user, artCnt); } return(RedirectToAction(model.BackAction, model.BackController, new { page = model.BackPage })); }
/// <summary> /// 新增網站會員 /// </summary> /// <param name="model">The model.</param> /// <param name="path">存放大頭照的實體路徑</param> public void CreateUser(MemberCreateViewModel model, string path) { using (var tranScope = new TransactionScope()) { // Table User var fileName = SaveMemberPic(model.File, path); var user = ConvertToUserEntity(model, $"{FileUploadPath}/{fileName}"); user.Id = _userRepo.Create(_conn, user); var userVm = ConvertToUserViewModel(user); // Table Password var password = ConvertToPassEntity(user.Id, user.Guid, model.Password); CreatePassword(password); // 註冊完直接給他登入-因為是新會員,所以文章count直接給預設0即可 SignInUser.UserLogin(true, userVm, new UserArticleCount()); tranScope.Complete(); } }
public ActionResult Login(MemberLoginViewModel model) { ViewBag.Title = "會員登入"; if (!ModelState.IsValid) { return(View(model)); } var loginResult = _memberService.CheckUserPassword(model.Account, model.Password); if (loginResult.Auth.Equals(false)) { ModelState.AddModelError("LoginError", "帳號或密碼錯誤"); return(View(model)); } var artCnt = _memberService.GetUserArticleCount(loginResult.User.Id); SignInUser.UserLogin(true, loginResult.User, artCnt); return(RedirectToAction("Index", "Post")); }