private void ValidateUserLoginRequest(UserSignInRequest request) { ValidationException exception = new ValidationException(); if (request == null) { exception.Add(new ValidationError("common.invalidRequest")); } if (string.IsNullOrWhiteSpace(request.Email)) { exception.Add(new ValidationError("registration.signin.validation.emailRequired")); } if (string.IsNullOrWhiteSpace(request.Pwd)) { exception.Add(new ValidationError("registration.signin.validation.pwdRequired")); } IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(); User userProfile = userRepository.GetByEmail(request.Email); if (userProfile == null || EncodeHelper.EncodePassword(request.Pwd) != userProfile.Password) { exception.Add(new ValidationError("registration.signin.validation.invalidEmailOrPwd")); } exception.ThrowIfError(); }
public User(string email, string pwd) { this.Email = email; this.Password = EncodeHelper.EncodePassword(pwd); this.Id = Guid.NewGuid(); this.LastLoggedInDate = DateTime.Now; this.TokenExpiredAfter = DateTime.Now; this.FirstName = "firstname"; this.LastName = "lastname"; this.LanguageCode = Configuration.Current.Localization.DefaultLanguageCode; }
private void ValidateUserLoginRequest(UserSignInRequest request) { if (request == null) { throw new ValidationException("Common.InvalidRequest"); } if (String.IsNullOrWhiteSpace(request.Email)) { throw new ValidationException("Registration.SignIn.InvalidEmail"); } if (String.IsNullOrWhiteSpace(request.Pwd)) { throw new ValidationException("Registration.SignIn.InvalidPwd"); } IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(); User userProfile = userRepository.GetByEmail(request.Email); if (userProfile == null || EncodeHelper.EncodePassword(request.Pwd) != userProfile.Password) { throw new ValidationException("Registration.SignIn.InvalidEmailOrPwd"); } }
public void Handle(CreateUserCommand command) { this.ValidateCreateUserRequest(command); using (IUnitOfWork uow = this.CreateUnitOfWork <User>()) { IUserRepository repository = IoC.Container.Resolve <IUserRepository>(uow); User user = new User(); user.FirstName = command.FirstName; user.LastName = command.LastName; user.Email = command.Email; user.UserName = command.UserName; user.Pwd = EncodeHelper.EncodePassword(command.Pwd); foreach (Role role in command.Roles) { user.AddRole(role); } repository.Add(user); uow.Commit(); command.Result = user.Id; user.PublishEvents(); } }
public void Handle(UserNameAndPwdAuthenticationRequest command) { this.ValidateUserNameAndPwdAuthenticationRequest(command); using (IUnitOfWork uow = this.CreateUnitOfWork <User>()) { IUserRepository repository = IoC.Container.Resolve <IUserRepository>(uow); User user = repository.GetActiveUser(command.UserName, EncodeHelper.EncodePassword(command.Password)); if (user == null) { command.Result = new AuthenticationResult(false); this.Publish(new OnAuthenticationFailed(command.UserName, command.Password, DateTime.UtcNow)); return; } user.GenerateLoginToken(); repository.Update(user); uow.Commit(); command.Result = ObjectHelper.Convert <AuthenticationResult>(user); command.Result.IsValid = true; this.Publish(new OnAuthenticationSuccess(user.FirstName, user.LastName, user.Email, user.LoginToken, user.TokenExpiredAfter, DateTime.UtcNow)); } }