public async Task <Result <AuthenticatedUserModel> > LoginAndGetLayout(LoginFromBody loginFromBody) { var authenticatedUserModel = new AuthenticatedUserModel(); var result = await Login(loginFromBody).OnSuccess(async res => { authenticatedUserModel.Id = res.Id; await GetTeamAsync(res.Id) .OnSuccess(async team => { authenticatedUserModel.Team = new TeamLocalModel() { Id = team.Id, Name = team.Name }; await GetLayoutAsync(team.Layout) .OnSuccess(layout => { authenticatedUserModel.Layout = layout.Diagram; }); }); }); if (result.IsSuccess) { return(Result.Ok(authenticatedUserModel)); } else { return(Result.Fail <AuthenticatedUserModel>(result.Error)); } }
public async Task <IActionResult> Login([FromQuery] LoginFromQuery query, [FromBody] LoginFromBody body) { var request = new LoginRequest(query, body); var result = await _apiResult.Produce(request); return(result); }
private async Task <Result <UserModel> > Login(LoginFromBody loginFromBody) { var jsonBody = JsonConvert.SerializeObject(loginFromBody); var response = await _usersRestApi.Login($"{UrlsConfig.Users}{UrlsConfig.UsersOperations.Login(_apiVersion)}", jsonBody); if (response.StatusCode == HttpStatusCode.Forbidden) { return(Result.Fail <UserModel>("Invalid credentials")); } else { var responseAsString = await response.Content.ReadAsStringAsync(); var authenticatedUser = JsonConvert.DeserializeObject <UserModel>(responseAsString); return(Result.Ok(authenticatedUser)); } }
public async Task <IActionResult> Login([FromBody] LoginFromBody login) { var result = await _mobileService.LoginAndGetLayout(login); if (result.IsSuccess) { var data = result.Value; var response = Envelope.Ok(data); return(Ok(response)); } else { var response = new JsonResult(Envelope.Error(result.Error)); response.StatusCode = (int)HttpStatusCode.Forbidden; return(response); } }
public LoginRequest(LoginFromQuery query, LoginFromBody body) { _body = body ?? throw new ArgumentNullException(nameof(body)); _query = query ?? throw new ArgumentException(nameof(query)); }