public async Task <UserDto> Login(string user, string password)
        {
            var pEncrypted = Encryptions.EncryptString(EncryptionConstants.Key, password);

            var userModel = await _authenticationRepository.GetUser(user, pEncrypted);

            if (userModel == null)
            {
                return(null);
            }
            userModel.IsLoggedIn  = true;
            userModel.UpdatedDate = DateTime.Now;

            _repositoryWrapper.User.Updete(userModel);

            await _repositoryWrapper.SaveAsync();

            var result = _mapper.Map <UserDto>(userModel);

            result.UserType = userModel.UserTypeId == 1 ? "Owner" : "Customer";

            result.Password = password;

            return(result);
        }
        public async Task <bool> CheckIsLoggedIn(string user, string password)
        {
            var pEncrypted = Encryptions.EncryptString(EncryptionConstants.Key, password);
            var userModel  = await _authenticationRepository.GetUser(user, pEncrypted);

            if (userModel == null || userModel.IsLoggedIn.Value == false)
            {
                return(false);
            }
            return(true);
        }
Пример #3
0
        public async Task <bool> CreateUser(UserRequest requestDto)
        {
            try
            {
                var userModel = _mapper.Map <UserModel>(requestDto);
                userModel.CreatedDate = DateTime.Now;
                userModel.UpdatedDate = DateTime.Now;
                userModel.IsLoggedIn  = false;
                var encryptedString = Encryptions.EncryptString(EncryptionConstants.Key, userModel.Password);
                userModel.Password = encryptedString;
                await _repositoryWrapper.User.CreateAsync(userModel);

                await _repositoryWrapper.SaveAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #4
0
        public async Task <bool> ChangePassword(int id, ChangePasswordRequest request)
        {
            try
            {
                var user = await _userRepository.GetUserById(id);

                await _repositoryWrapper.BeginTransactionAsync();

                var Encrypassword = Encryptions.DecryptString(EncryptionConstants.Key, user.Password);

                if (Encrypassword == request.OldPassword)
                {
                    var encryptPassword = Encryptions.EncryptString(EncryptionConstants.Key, request.NewPassword);

                    user.Password = encryptPassword;
                }
                else
                {
                    return(false);
                }
                _repositoryWrapper.User.Updete(user);

                await _repositoryWrapper.SaveAsync();

                await _repositoryWrapper.CommitAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                _repositoryWrapper.Dispose();
            }
        }