public ActionResult Registration(UserModelWithPassword user)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("Registration", "Authorisation"));
     }
     if (_userServices.UserExists(user.Email))
     {
         ModelState.AddModelError("Email", "This email  " + user.Email + "  already exist!");
         return(View());
     }
     try
     {
         _userServices.Create(user);
         var newUser = _userServices
                       .GetUserByEmail(user.Email);
         var identity = new ClaimsIdentity(new[] {
             new Claim("Id", newUser.Id.ToString()),
             new Claim(ClaimTypes.Email, newUser.Email),
             new Claim(ClaimTypes.Name, newUser.FirstName),
             new Claim(ClaimTypes.Role, newUser.Role.ToString())
         },
                                           DefaultAuthenticationTypes.ApplicationCookie);
         var ctx         = Request.GetOwinContext();
         var authManager = ctx.Authentication;
         authManager.SignIn(identity);
         return(Redirect(GetRedirectUrl(null)));
     }
     catch
     {
         return(RedirectToAction("Registration", "Authorisation"));
     }
 }
Exemplo n.º 2
0
        public void Create(UserModelWithPassword model)
        {
            var salt     = PasswordHashHelper.CreateSaltForPasscode();
            var passcode = PasswordHashHelper.GetCodeForPassword(model.Password, salt);

            _userRepository.Add(model.FirstName, model.LastName, model.Email, UserRole.User, passcode, salt);
        }
Exemplo n.º 3
0
        public void Update(int id, UserModelWithPassword model)
        {
            var salt     = _userRepository.GetUserById(id).Salt;
            var password = PasswordHashHelper.GetCodeForPassword(model.Password, salt);

            _userRepository.Update(id, password);
        }
Exemplo n.º 4
0
 public ActionResult ResetPassword(int id, UserModelWithPassword user)
 {
     try
     {
         _userServices.Update(id, user);
         return(this.User.IsInRole("Admin") ? RedirectToAction("Index") : RedirectToAction("Profile"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 5
0
 public ActionResult Create(UserModelWithPassword user)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     if (_userServices.UserExists(user.Email))
     {
         ModelState.AddModelError("Email", "This email   " + user.Email + "   already exist!");
         return(View());
     }
     _userServices.Create(user);
     return(RedirectToAction("Index"));
 }