Exemplo n.º 1
0
 public ClaimsIdentity Authenticate(ApplicationUserDTO userDto)
 {
     ClaimsIdentity claim = null;
     ApplicationUserEntity user = _userRepository.Find(userDto.UserName, userDto.Password);
     if (user != null)
         claim = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
     return claim;
 }
Exemplo n.º 2
0
 public OperationDetails DeleteUser(ApplicationUserDTO user)
 {
     ApplicationUserEntity appUser = _userRepository.FindByName(user.UserName);
     if (appUser != null)
     {
         _userRepository.Delete(appUser);
         _uow.Commit();
         return new OperationDetails(true, "Удаление прошло успешно", "");
     }
     return new OperationDetails(false, "Пользователь, который должен быть удален не существует", "");
 }
Exemplo n.º 3
0
 public OperationDetails CreateUser(ApplicationUserDTO user)
 {
     var appUser = _userRepository.FindByName(user.UserName);
     if (appUser == null)
     {
         appUser = new ApplicationUserEntity { UserName = user.UserName, UserProfileName = user.UserProfileName };
         _userRepository.CreateUserEntity(appUser,user.Password);
         //_uow.Commit();
         return new OperationDetails(true, "Регистрация успешно пройдена", "");
     }
     return new OperationDetails(false, "Пользователь с таким email уже существует", "");
 }
 public ActionResult Login(LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         ApplicationUserDTO userDto = new ApplicationUserDTO { UserName = model.Email, Password = model.Password };
         ClaimsIdentity claim = _userService.Authenticate(userDto);
         if (claim == null)
         {
             ModelState.AddModelError("", "Неверный логин или пароль.");
         }
         else
         {
             AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
             AuthenticationManager.SignIn(new AuthenticationProperties
             {
                 IsPersistent = model.IsPersistent
             }, claim);
             return RedirectToAction("Index", "Home");
         }
     }
     return View(model);
 }
 public ActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         ApplicationUserDTO userDto = new ApplicationUserDTO
         {
             UserName = model.Email,
             Password = model.Password,
             UserProfileName = model.UserProfileName
         };
         OperationDetails operationDetails = _userService.CreateUser(userDto);
         if (operationDetails.Succedeed)
             return RedirectToAction("Login", "Account");
         ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
     }
     return View(model);
 }