Example #1
0
        public async Task <AppLoginResult> AppLoginAsync(AppLoginDto request)
        {
            var appEntity = await this._appRepository.QueryFirstAsync(x => x.AppCode == request.AppCode);

            if (appEntity.AppScret != request.AppSecret)
            {
                throw new EasyRbacException("app code/securet erro");
            }
            var login = new LoginTokenEntity()
            {
                UserId   = appEntity.Id,
                CreateOn = DateTime.Now,
                ExpireIn = (int)TimeSpan.FromDays(1).TotalSeconds,
                Token    = $"A{this._numberConvert.ToString(appEntity.Id)}-{DateTime.Now:MMddHHmmss}-{Guid.NewGuid():N}"
            };

            await this._loginTokenRepository.InsertAsync(login);

            return(new AppLoginResult()
            {
                ExpireIn = login.ExpireIn,
                Token = login.Token
            });
        }
Example #2
0
        public async Task <ActionResult <AppUserDto> > Authenticate([FromBody] AppLoginDto appLoginDto)
        {
            var user = await _userService.Authenticate(appLoginDto.Username, appLoginDto.Password);

            if (user == null)
            {
                return(BadRequest(new ApiErrorDto {
                    Message = "Username or password is incorrect"
                }));
            }

            if (!user.IsRegistrationAccepted())
            {
                return(BadRequest(new ApiErrorDto {
                    Message = "User is not yet accepted. Please contact the admin."
                }));
            }

            var respUserDto = _mapper.Map <AppUserDto>(user);

            respUserDto.Token = _tokenManager.GenerateToken(user);

            return(respUserDto);
        }
Example #3
0
 public Task <AppLoginResult> AppLogin(AppLoginDto dto)
 {
     return(this._loginService.AppLoginAsync(dto));
 }
Example #4
0
        public async Task <AppLoginResult> AppLogin([FromBody] AppLoginDto dto)
        {
            var result = await this._loginService.AppLoginAsync(dto);

            return(result);
        }