/// <summary> /// JWT. Войти в систему. /// </summary> /// <param name="input">Ввод.</param> /// <returns>Задача с выводом.</returns> public async Task <ModAuthBaseCommonJobLoginJwtOutput> JwtLogin(ModAuthBaseCommonJobLoginInput input) { ModAuthBaseCommonJobLoginJwtOutput result = null; if (!string.IsNullOrEmpty(input.DataPassword)) { DataEntityObjectUser user = null; var userManager = input.UserManager; if (!string.IsNullOrEmpty(input.DataUserName)) { user = await userManager.FindByNameAsync(input.DataUserName) .CoreBaseExtTaskWithCurrentCulture(false); } else if (!string.IsNullOrEmpty(input.DataEmail)) { user = await userManager.FindByEmailAsync(input.DataEmail) .CoreBaseExtTaskWithCurrentCulture(false); } if (user != null) { var isOk = await userManager.CheckPasswordAsync(user, input.DataPassword) .CoreBaseExtTaskWithCurrentCulture(false); if (isOk) { result = await user.ModAuthBaseExtCreateHostBasePartAuthJobLoginJwtOutput( userManager, JwtService ); } } } if (result == null) { throw new ModAuthBaseCommonJobLoginException(); } return(result); }
public async Task <IActionResult> Login([FromBody] ModAuthBaseCommonJobLoginInput input) { var result = new ModAuthBaseCommonJobLoginJwtResult(); var(execute, onSuccess, onError) = MyModel.BuildActionLogin(input); try { result.Data = await execute().CoreBaseExtTaskWithCurrentCulture(false); onSuccess(result); } catch (Exception ex) { onError(ex, result); } return(Ok(result)); }
) BuildActionLogin(ModAuthBaseCommonJobLoginInput input) { input.UserManager = ExtUserManager; var job = AppJobLogin; Task <ModAuthBaseCommonJobLoginJwtOutput> execute() => job.Execute(input); void onSuccess(ModAuthBaseCommonJobLoginJwtResult result) { job.OnSuccess(ExtLogger, result, input); } void onError(Exception ex, ModAuthBaseCommonJobLoginJwtResult result) { job.OnError(ex, ExtLogger, result); } return(execute, onSuccess, onError); }