public ActionResult Index(RegistrationModel regModel) { if(!ModelState.IsValid) return View(regModel); if(regModel.Password1 != regModel.Password2) { ViewData["RegisterResultMessage"] = "Введеные вами пароли не совпадают."; return View(regModel); } var user = new User { Username = regModel.Username, Password = regModel.Password1 }; switch(usersService.RegisterUser(user)) { case UserRegisterState.UsernameIsAlreadyUsed: { ViewData["RegisterResultMessage"] = "Пользователь с именем " + regModel.Username + " уже существует. Попробуйте другое имя."; return View(regModel); } case UserRegisterState.SomeAnotherError: { ViewData["RegisterResultMessage"] = "Произошло чего то непонятное."; return View(regModel); } case UserRegisterState.Succes: { ViewData["RegisterResultMessage"] = "Пользователь " + regModel.Username + " успешно зарегестрирован!"; return View(regModel); } default : return View(regModel); } }
public bool DeleteUser(User user) { try { userRepository.DeleteUser(user); //TODO удаление блога сделать в IBlogService blogsRepository.DeleteBlog(new Blog() {Director = user}); return true; } catch(Exception ex) { return false; } }
public UserRegisterState RegisterUser(User user) { if(userRepository.Users.FirstOrDefault(p => p.Username == user.Username) != null) { return UserRegisterState.UsernameIsAlreadyUsed; } try { userRepository.AddUser(user); //TODO добавление блога для пользователя сделать в IBlogService blogsRepository.AddBlog(new Blog() { Director = user }); return UserRegisterState.Succes; } catch(Exception ex) { return UserRegisterState.SomeAnotherError; } }
public ActionResult LogIn(AuthenticationModel authModel) { if (!ModelState.IsValid) return View(authModel); var user = new User { Username = authModel.Username, Password = authModel.Password }; if(!usersService.ValidateUser(user)) { ViewData["AuthenticationResultMessage"] = "Вы ввели не верное имя или пароль. Попробуйте еще раз"; return View(authModel); } authService.SignIn(user); return View(authModel); }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="username">Initial value of the Username property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="createdOn">Initial value of the CreatedOn property.</param> /// <param name="email">Initial value of the Email property.</param> public static User CreateUser(global::System.Int32 id, global::System.String username, global::System.String password, global::System.DateTime createdOn, global::System.String email) { User user = new User(); user.Id = id; user.Username = username; user.Password = password; user.CreatedOn = createdOn; user.Email = email; return user; }
//private IUsersRepository context = new FakeUsersRepository(); /// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> // public SqlAuthenticationService(IUsersRepository context) { // this.context = context; // } public void SignIn(User user) { FormsAuthentication.SetAuthCookie(user.Username, true); }
public bool ValidateUser(User user) { throw new NotImplementedException(); }
public UserRegisterState RegisterUser(User user) { throw new NotImplementedException(); }
public bool DeleteUser(User user) { throw new NotImplementedException(); }
public bool ValidateUser(User user) { return userRepository.Users.WithUsernameAndPassword(user.Username, user.Password) != null; }