Skip to content

Instantly share code, notes, and snippets.

@nest-don
Last active June 18, 2019 10:01
Show Gist options
  • Save nest-don/757b0ace09cb85fad6e3826a4b39c55f to your computer and use it in GitHub Desktop.
Save nest-don/757b0ace09cb85fad6e3826a4b39c55f to your computer and use it in GitHub Desktop.
public enum Result
{
Succeeded = 0,
Failed = -1,
Unauthorized = -5,
InternalError = -10,
UserNotFound = -15,
IncorrectEmail = -20,
EmailNotConfirmed = -25,
IncorrectSecurityCode = -30,
InvalidPermit = -35,
InvalidShare = -40,
LoginFailed = -45
}
// GET api/permits/{email}
[HttpGet("{email}")]
public async Task<object> QueryTokenAsync(string email, [FromQuery] string password)
{
if (string.IsNullOrEmpty(email))
{
return this.NestResult(Result.IncorrectEmail);
}
var result = await _signInManager.PasswordSignInAsync(email, password, false, false);
if (result.Succeeded)
{
Permit permit = new Permit();
permit.Password = password;
permit.Owner = await _userManager.FindByNameAsync(email);
permit.Token = await GenerateJwtTokenAsync(permit.Owner);
return this.NestResultSingle(
Result.Succeeded, permit, "A new token has been created for the permit");
}
return this.NestResult(Result.LoginFailed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment