Beispiel #1
0
            public IdentityUser Resolve(Register.Command source, AppUser dest, IdentityUser destMember, ResolutionContext context)
            {
                string salt = _cryptoHelper.CreateBase64Salt();

                return(new IdentityUser
                {
                    UserName = source.UserName,
                    Salt = salt,
                    Passoword = _cryptoHelper.GenerateHash(source.Password, salt),
                    RefreshToken = _jwtGenerator.CreateRefreshToken(),
                    RefreshTokenExpiry = HelperFunc.GetCurrentDateTime().AddDays(30)
                });
            }
        public LoginResponse LoginUser(LoginRequest loginRequest)
        {
            var user = _userRepository.Find(c =>
                                            c.Email == loginRequest.Email &&
                                            c.Password == _crypoHelper.GenerateHash(loginRequest.Password));

            if (user == null)
            {
                return(null);
            }

            var token   = _tokenService.GenerateToken(user);
            var balance = _movementRepository.GetBalance(user.Id);

            return(new LoginResponse
            {
                UserId = user.Id,
                UserEmail = user.Email,
                DotsBalance = balance,
                UserRole = user.Role,
                Token = token
            });
        }
Beispiel #3
0
            public async Task <UserDto> Handle(Command request, CancellationToken cancellationToken)
            {
                IdentityUser identityUser = await _unitOfWork.IdentityUserRepo.FindFirstAsync(request.UserName, cancellationToken);

                if (identityUser == null)
                {
                    throw new CustomException(HttpStatusCode.Unauthorized);
                }

                if (_cryptoHelper.GenerateHash(request.Password, identityUser.Salt) == identityUser.Passoword)
                {
                    identityUser.PreviousRefreshToken       = null;
                    identityUser.PreviousRefreshTokenExpiry = null;
                    identityUser.RefreshToken       = _jwtGenerator.CreateRefreshToken();
                    identityUser.RefreshTokenExpiry = HelperFunc.GetCurrentDateTime().AddDays(30);
                    _unitOfWork.IdentityUserRepo.Update(identityUser);

                    await _unitOfWork.SaveAsync(cancellationToken);

                    return(_mapperHelper.Map <IdentityUser, UserDto>(identityUser));
                }
                throw new CustomException(HttpStatusCode.Unauthorized);
            }