예제 #1
0
        public async Task <LoginReturnDTO> Logout([FromBody] LoginModel user)
        {
            if (user == null)
            {
                return(new LoginReturnDTO(ErrCode.LoginEmpty));
            }
            string tokenString = string.Empty;
            bool   validUser   = await _userService.Authenticate(user);

            if (validUser)
            {
                tokenString = await _userService.GenerateToken(user);
            }
            else
            {
                return(new LoginReturnDTO(ErrCode.PassWrong));
            }
            var info = new LoginReturnDTO
            {
                Msg   = "Login successfully",
                Token = tokenString
            };

            return(info);
        }
예제 #2
0
        public LoginReturnDTO Login(LoginInfoDTO loginInfo)
        {
            LoginReturnDTO lrd = new LoginReturnDTO();

            User user = uow.UserRepository.GetByUsername(loginInfo.Username);

            if (user == null)
            {
                lrd.IsSuccess = false;
                lrd.Message   = "Username and/or password are incorect";
            }
            else if (user.Blocked)
            {
                lrd.IsSuccess = false;
                lrd.Message   = "Account is blocked by administrator";
            }
            else if (user.Password.Equals(loginInfo.Password))
            {
                lrd.IsSuccess = true;
                lrd.User      = user;
                lrd.Message   = "Success";


                UserPrincipal principal = new UserPrincipal(user, true);
                SetPrincipal(principal);
            }

            return(lrd);
        }
예제 #3
0
        public async Task <LoginReturnDTO> Login([FromBody] LoginModel user)
        {
            if (user == null)
            {
                return(new LoginReturnDTO(ErrCode.LoginEmpty));
            }
            string tokenString = string.Empty;
            bool   validUser   = await _userService.Authenticate(user);

            if (validUser)
            {
                tokenString = await _userService.GenerateToken(user);
            }
            else
            {
                return(new LoginReturnDTO(ErrCode.PassWrong));
            }
            var info = new LoginReturnDTO
            {
                Msg   = "Login successfully",
                Token = tokenString,
                Info  = _mapper.Map <GetUserDTO>(await _repositoryWrapper.UserRepo.CheckUser(user))
            };

            return(info);
        }