/// <summary> /// 登录 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <AdminLoginDto> LoginAsync(LoginAdminDto input) { AdminUser user; if (input.Type == LoginType.Account) { user = await _userRepository .Where(a => a.LoginName == input.Identifer) .ToOneAsync(); ThrowIf(user == null, new AdminUserNotExistsException(input.Identifer)); var password = LgbCryptography.ComputeHash(input.Credential, user.PasswordSalt); ThrowIf(user.Password != password, new PasswordWrongException()); } else { user = await _userRepository .Where(a => a.Phone == input.Identifer) .FirstAsync(); ThrowIf(user == null, new AdminUserNotExistsException(input.Identifer)); var cacheKey = SystemCacheKeyPrefixDefinition.LoginCaptcha + input.Identifer; var captcha = await Cache.GetAsync(cacheKey); ThrowIf(captcha.IsNullOrWhiteSpace(), new UnGetCaptchaException()); ThrowIf(captcha != input.Credential, new CaptchaWrongException()); } return(Mapper.Map <AdminLoginDto>(user)); }
public async Task <JsonResultModel <String> > CreateTokenAsync([FromBody] LoginAdminDto input) { var loginUser = await _service.LoginAsync(input); string token = string.Empty; if (loginUser is { Id : > 0 })
public async Task <IActionResult> Login([FromBody] LoginAdminDto model) { try { if (ModelState.IsValid) { var result = await _authenticationService.DoLogin(new LoginDto { Cpf = model.Login, Password = model.Password }, ""); if (result.authenticated) { _logger.Info($"Tentativa de login na api de resgate com cpf {model.Login} - {result.messageReturning}"); return(Ok(new { message = result.messageReturning, token = GenerateJwtToken(result.user) })); } else { _logger.Fatal($"Tentativa de login na api de resgate com cpf {model.Login} - {result.messageReturning}"); return(NotFound(result.messageReturning)); } } else { _logger.Fatal($"Tentativa de login na api de resgate com cpf {model.Login} rejeitada pela validação"); return(BadRequest(ModelState)); } } catch (Exception ex) { #if (!DEBUG) _logger.Fatal($"Tentativa de login na api de resgate com cpf {model.Login} - {ex.ToLogString(Environment.StackTrace)}"); #endif return(BadRequest($"Tentativa de login na api de resgate com cpf {model.Login} - {ex.ToLogString(Environment.StackTrace)}")); } }
public IActionResult Authenticate([FromBody] LoginAdminDto input) { var admin = context.Set <Administrator>().FirstOrDefault(a => a.Login == input.Login); if (admin == null || !PasswordHash.FromBase64(admin.PasswordHash).Verify(input.Password)) { return(BadRequest()); } return(Ok(tokenService.CreateTokenObject(admin))); }