public IActionResult EditProfile(EditProfileViewModel profile) { if (!ModelState.IsValid) { return(View(profile)); } if (_userService.IsExistUserNameForEdit(profile.UserName, User.Identity.Name)) { ModelState.AddModelError("UserName", "نام کاربری قبلا ثبت شده است ."); return(View(profile)); } if (_userService.IsExistEmailForEdit(FixedText.FixEmail(profile.Email), User.Identity.Name)) { ModelState.AddModelError("Email", "ایمیل معتبر نمی باشد"); return(View(profile)); } _userService.EditProfile(User.Identity.Name, profile); //Log Out User HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return(Redirect("/Login?EditProfile=true")); }
public User LoginUser(LoginViewModel login) { string hashPassword = PasswordHelper.EncodePasswordMd5(login.Password); string email = FixedText.FixEmail(login.Email); return(_context.Users.SingleOrDefault(u => u.Email == email && u.Password == hashPassword)); }
public IActionResult Register(RegisterViewModel register) { if (!ModelState.IsValid) { return(View(register)); } if (_userService.IsExistUserName(register.UserName)) { ModelState.AddModelError("UserName", "نام کاربری معتبر نمی باشد"); return(View(register)); } if (_userService.IsExistEmail(FixedText.FixEmail(register.Email))) { ModelState.AddModelError("Email", "ایمیل معتبر نمی باشد"); return(View(register)); } DataLayer.Entities.User.User user = new User() { ActiveCode = NameGenerator.GenerateUniqCode(), Email = FixedText.FixEmail(register.Email), IsActive = false, Password = PasswordHelper.EncodePasswordMd5(register.Password), RegisterDate = DateTime.Now, UserAvatar = "Defult.jpg", UserName = register.UserName }; _userService.AddUser(user); return(View("SuccessRegister", user)); }
public IActionResult OnPost(int id, List <int> SelectedRoles) { var user = _userService.GetUserByID(id); if (!ModelState.IsValid) { ViewData["Roles"] = _permissionService.GetRoles(); InfoForEditUser = _userService.GetUserInfoForEdit(id); return(Page()); } if (_userService.IsExistUserName(InfoForEditUser.UserName) && InfoForEditUser.UserName != user.UserName) { ModelState.AddModelError("InfoForEditUser.UserName", "نام کاربری تکراری است."); return(Page()); } if (_userService.IsExistPhoneNumber(InfoForEditUser.PhoneNumber) && InfoForEditUser.PhoneNumber != user.PhoneNumber) { ModelState.AddModelError("InfoForEditUser.PhoneNumber", "شماره موبایل تکراری است"); } if (InfoForEditUser.Email != null) { if (user.Email != null) { if (_userService.IsExistEmail(FixedText.FixEmail(InfoForEditUser.Email)) && InfoForEditUser.Email != user.Email) { ModelState.AddModelError("InfoForEditUser.Email", "ایمیل تکراری است."); } } } _userService.EditUserFromAdmin(InfoForEditUser); _permissionService.EditUserRoles(SelectedRoles, id); return(RedirectToPage("Index")); }
public IActionResult EditProfile(EditProfileViewModel info) { var user = _userService.GetUserByUserName(User.Identity.Name); if (!ModelState.IsValid) { return(View(info)); } if (_userService.IsExistUserName(info.UserName) && info.UserName != user.UserName) { ModelState.AddModelError("UserName", "این نام کاربری قبلا ثبت شده است."); } if (_userService.IsExistPhoneNumber(info.PhoneNumber) && info.PhoneNumber != user.PhoneNumber) { ModelState.AddModelError("PhoneNumber", "این شماره موبایل قبلا ثبت شده است."); return(View(info)); } if (info.Email != null) { if (_userService.IsExistEmail(FixedText.FixEmail(info.Email)) && info.Email != user.Email) { ModelState.AddModelError("Email", "این ایمیل قبلا ثبت شده است."); return(View(info)); } } _userService.EditProfile(User.Identity.Name, info); //Logout User HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return(Redirect("/Login?EditProfile=true")); }
public IActionResult OnPost(List <int> selectedRoles) { if (!ModelState.IsValid) { EditUserViewModel = _userService.GetUserForShowInEditMode(EditUserViewModel.UserId); ViewData["Roles"] = _permissionService.GetRoles(); return(Page()); } if (_userService.IsExistEmailForEdit(FixedText.FixEmail(EditUserViewModel.Email), EditUserViewModel.OldUserName)) { EditUserViewModel = _userService.GetUserForShowInEditMode(EditUserViewModel.UserId); ViewData["Roles"] = _permissionService.GetRoles(); ViewData["IsExistEmail"] = true; return(Page()); } if (_userService.IsExistUserNameForEdit(EditUserViewModel.UserName, EditUserViewModel.OldUserName)) { EditUserViewModel = _userService.GetUserForShowInEditMode(EditUserViewModel.UserId); ViewData["Roles"] = _permissionService.GetRoles(); ViewData["IsExistUserName"] = true; return(Page()); } _userService.EditUserFromAdmin(EditUserViewModel); //Edit Roles _permissionService.EditRolesUser(EditUserViewModel.UserId, selectedRoles); return(RedirectToPage("Index")); }
public IActionResult Register(RegisterViewModel register) { if (!ModelState.IsValid) { return(View(register)); } if (_userService.IsExistUserName(register.UserName)) { ModelState.AddModelError("UserName", "نام کاربری معتبر نمی باشد"); return(View(register)); } if (_userService.IsExistEmail(FixedText.FixEmail(register.Email))) { ModelState.AddModelError("Email", "ایمیل معتبر نمی باشد"); return(View(register)); } User user = new User() { ActiveCode = NameGenerator.GenerateUniqCode(), Email = FixedText.FixEmail(register.Email), IsActive = false, Password = PasswordHelper.EncodePasswordMd5(register.Password), RegisterDate = DateTime.Now, UserAvatar = "Defult.jpg", UserName = register.UserName }; _userService.AddUser(user); #region SendEmail string body = _viewRender.RenderToStringAsync("_ActiveEmail", user); SendEmail.Send(user.Email, "فعالسازی", body); #endregion return(View("SuccessRegister", user)); }
public About LoginUser(LoginViewModel login) { string email = FixedText.FixEmail(login.Email); string hashpass = PasswordHelper.EncodePasswordMd5(login.Password); return(db.Abouts.SingleOrDefault(u => u.Email == email && u.Password == hashpass)); }
public IActionResult Register(RegisterViewModel register) { #region چک کردن اعتبار سنجی ها و عدم وجود نام کاربری و ایمیل if (!ModelState.IsValid) { return(View(register)); } if (_userService.isExistEmail(FixedText.FixEmail(register.Email))) { ModelState.AddModelError("Email", "این ایمیل موجود می باشد"); return(View(register)); } if (_userService.isExistUserName(FixedText.FixEmail(register.UserName))) { ModelState.AddModelError("UserName", "این نام کاربری معتبر نمی باشد"); return(View(register)); } #endregion #region ثبت کاربر DataLayer.Entities.User.User user = new DataLayer.Entities.User.User() { ActiveCode = NameGenerator.GenerateUniqCode(), Email = FixedText.FixEmail(register.Email), IsActive = false, Password = PasswordHelper.EncodePasswordMd5(register.Password), RegisterDate = DateTime.Now, UserAvatar = "Defult.jpg", UserName = register.UserName, }; _userService.AddUser(user); #endregion #region ارسال ایمیل فعال سازی string body = _ViewRender.RenderToStringAsync("_ActiveEmail", user); SendEmail.Send(user.Email, "فعالسازی", body); #endregion return(View("SuccessRegister", user)); }
public IActionResult ForgotPassword(ForgotPasswordViewModel forgot) { if (!ModelState.IsValid) { return(View(forgot)); } string fixedEmail = FixedText.FixEmail(forgot.Email); var user = _userService.GetUserByEmail(fixedEmail); if (user == null) { ModelState.AddModelError("Email", "کاربری یافت نشد"); return(View(forgot)); } string bodyEmail = _viewRender.RenderToStringAsync("_ForgotPassword", user); SendEmail.Send(user.Email, "بازیابی حساب کاربری", bodyEmail); ViewBag.IsSuccess = true; return(View()); }
public IActionResult Register(RegisterViewModel register) { if (!ModelState.IsValid) { return(View(register)); } if (_userService.IsExistUserName(register.UserName)) { ModelState.AddModelError("UserName", "این نام کاربری قبلا ثبت شده است."); return(View(register)); } if (_userService.IsExistPhoneNumber(register.PhoneNumber)) { ModelState.AddModelError("PhoneNumber", "این شماره موبایل قبلا ثبت شده است."); return(View(register)); } if (register.Email != null) { if (_userService.IsExistEmail(FixedText.FixEmail(register.Email))) { ModelState.AddModelError("Email", "این ایمیل قبلا ثبت شده است."); return(View(register)); } } DataLayer.Entities.User.User user = new DataLayer.Entities.User.User() { UserName = register.UserName, PhoneNumber = register.PhoneNumber, Email = register.Email, Password = PasswordHelper.EncodePasswordMd5(register.Password), ActiveCode = NameGenerator.GenerateUniqCode(), RegisterDate = DateTime.Now, }; _userService.AddUser(user); return(View("SuccessRegister", user)); }
public IActionResult Register(RegisterViewModel registerViewModel) { if (!ModelState.IsValid) { return(View(registerViewModel)); } if (_userService.IsExistUserName(registerViewModel.UserName)) { ModelState.AddModelError("UserName", "نام کاربری معتبر نیست"); return(View(registerViewModel)); } if (_userService.IsExistEmail(FixedText.FixEmail(registerViewModel.UserEmail))) { ModelState.AddModelError("UserEmail", "ایمیل معتبر نیست"); return(View(registerViewModel)); } // TODO: REGISTER USER User user = new User() { UserActiveCode = NameGenerator.GenerateUniqueCode(), UserEmail = FixedText.FixEmail(registerViewModel.UserEmail), UserName = registerViewModel.UserName, UserIsActive = false, UserPassword = PasswordHelper.EncodePasswordMD5(registerViewModel.UserPassword), UserRegisterDate = DateTime.Now, UserAvatar = "Default.jpg" }; _userService.AddUser(user); return(View("SuccessRegister", user)); }