public ActionResult SignIn(BlogUserViewModel blogUserViewModel) { if (ModelState.IsValid) { try { BlogUserService.CreateBlogUser(blogUserViewModel); return(RedirectToAction("Index", "Home")); } catch (ApplicationException) { return(View()); } } return(View()); }
public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewModel) { if (ModelState.IsValid) { try { BlogUserService.ChangePassword(new BlogUserViewModel { UserName = AuthProvider.GetCurrentUser(), UserPassword = changePasswordViewModel.UserPassword, }); return(RedirectToAction("Index", "Home")); } catch (Exception) { return(View()); } } return(View()); }
public bool Authenticate(string userName, string password) { try { BlogUserViewModel newbloguserViewModel = BlogUserService.GetBlogUserNameAndPassword(new BlogUserViewModel { UserName = userName, UserPassword = password }); try { BlogUserService.GetAdminPermission(newbloguserViewModel.UserName); AuthTicket = new FormsAuthenticationTicket( 1, userName, DateTime.Now, DateTime.Now.AddMinutes(20), false, "Admin" ); } catch (Exception) { AuthTicket = new FormsAuthenticationTicket( 1, userName, DateTime.Now, DateTime.Now.AddMinutes(20), false, "User" ); } var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(AuthTicket)); HttpContext.Current.Response.Cookies.Add(authCookie); return(true); } catch (Exception) { return(false); } }