Esempio n. 1
0
        public bool Login(User user)
        {
            //1.检查
            if (string.IsNullOrEmpty(user.Email) || string.IsNullOrEmpty(user.Password))
            {
                return(false);
            }
            //2.按邮箱获取信息
            var taget = _userRepository.GetByEmail(user.Email);

            if (taget == null)
            {
                return(false);
            }
            //3.密码错误
            if (!taget.Password.Equals(user.Password))
            {
                return(false);
            }
            //4.更新信息
            taget.LastLoginTime = DateTime.Now;
            _userRepository.Update(user);

            return(true);
        }
Esempio n. 2
0
        public async Task <CommandResponse> Handler(SingInUserRequest singIn)
        {
            if (string.IsNullOrEmpty(singIn?.Email) || string.IsNullOrWhiteSpace(singIn?.Password))
            {
                _notificationContext.AddNotification("SingIn", Messages.MISSING_FIELDS);
                return(BadRequest(null, Messages.MISSING_FIELDS));
            }

            var user = await _userRepository.GetByEmail(singIn.Email);

            if (user == null || !user.isValidPass(singIn.Password))
            {
                _notificationContext.AddNotification("SingIn", Messages.INVALID_EMAIL_OR_PASSWORD);
                return(NotFound(null, Messages.INVALID_EMAIL_OR_PASSWORD));
            }

            user.UpdateLastLogin();

            _ = _userRepository.RegisterAccess(user);

            return(Ok(_mapper.Map <UserResponse>(user), Messages.SING_IN));
        }
        public async Task <CommandResponse> Handler(string login)
        {
            if (string.IsNullOrWhiteSpace(login))
            {
                _notificationContext.AddNotification("Login", Messages.MISSING_FIELDS);
                return(BadRequest(login, Messages.MISSING_FIELDS));
            }

            var user = await _userRepository.GetByEmail(login);

            if (user == null)
            {
                _notificationContext.AddNotification("Login", Messages.NOT_FOUND_USER);
                return(NotFound(login, Messages.NOT_FOUND_USER));
            }

            return(Ok(_mapper.Map <UserResponse>(user), null));
        }