Exemple #1
0
        public ClientAuthModel SendRequestLoginPost(ClientSignInModel clientSignUpModel)
        {
            var response = new RestRequestBuilder(NewBookModelsUrl.GetBaseUrl("1"), NewBookModelsUrl.Auth.SingIn())
                           .AddParametersAsJsonRowInRequestBody(clientSignUpModel)
                           .AddMethodType(Method.POST)
                           .AddHeader("content-type", "application/json")
                           .AddRequestFormat(DataFormat.Json)
                           .Execute();

            return(JsonConvert.DeserializeObject <ClientAuthModel>(response.Content));
        }
Exemple #2
0
        public async Task <ActionResult <ClientAuthenticationProfileModel> > SignIn([FromBody] ClientSignInModel clientSignInModel) => await Exec(async operation =>
        {
            if (User.Identity.IsAuthenticated)
            {
                throw new Exception(ExceptionMessage.UserHasAlreadyAuthenticated);
            }

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception(ExceptionMessage.ClientSignInFailedDueToInvalidModel);
                }
                var profile = await userAuthenticationService.TrySignIn(operation, clientSignInModel.ToEntity());
                await LoginChallenge(profile, UserRole.Client);
                return(new ClientAuthenticationProfileModel().ToModel(profile));
            }
            catch
            {
                await LogoutChallenge();
                throw;
            }
        });