Example #1
0
        public async Task <ActionResult> Authenticate(AuthenticateModel data)
        {
            try
            {
                var webSignature = await GoogleJsonWebSignatureEx.ValidateAsync(data.GoogleSignInIdToken);

                ActionResult checkError = CheckWebSignature(webSignature);

                if (checkError != null)
                {
                    return(checkError);
                }

                var authenticationResult = await _backofficeMembershipClient.AuthenticateAsync(
                    new AuthenticationDataModel
                {
                    UserId    = webSignature.Email,
                    Code      = data.Code,
                    Ip        = this.GetIp(),
                    SessionId = this.GetSession(),
                    UseTwoFactorVerification = _twoFactorVerificationSettings.UseVerification
                });

                if (authenticationResult.Result == AuthenticationResult.UserNotRegistered ||
                    authenticationResult.Result == AuthenticationResult.SecondFactorIsFailed)
                {
                    return(this.JsonFailResult(Phrases.UserNotRegistered, "#googleSignIn"));
                }

                if (authenticationResult.Result == AuthenticationResult.UserIsDisabled)
                {
                    return(this.JsonFailResult(Phrases.UserIsDisabled, "#googleSignIn"));
                }

                await SignIn(authenticationResult.User);
            }
            catch (InvalidJwtException ex)
            {
                _log.Info($"Invalid Jwt: {ex}");
                return(this.JsonFailResult(Phrases.InvalidJwt, "#googleSignIn"));
            }

            var divResult = Request.IsMobileBrowser() ? "#pamain" : "body";

            _log.Info("Authenticate success");

            return(this.JsonRequestResult(divResult, Url.Action(nameof(BackOfficeController.Layout), "BackOffice")));
        }