コード例 #1
0
        public object ValidateAndCreateAccessToken(AudienceCredentials credentials)
        {
            User audience = null;

            _loginUserValidators.Validate(credentials);
            audience = _accessTokenRepository.ValidateLoginUserCedential(credentials);

            var userByEmail = _accessTokenRepository.GetUserByEmail(credentials.Username);

            if (audience != null)
            {
                if (!audience.IsVerified)
                {
                    var loginErrorResponse = new EmailUnverifiedResponse
                    {
                        UserId     = audience.Id,
                        IsVerified = audience.IsVerified,
                        Message    = "Din emailadress är inte verifierad än. Vill du att vi skickar ett nytt mail?"
                    };
                    var validateLoginErrorResponse = new LoginUnVerifiedEmailResponse
                    {
                        data = loginErrorResponse
                    };
                    return(validateLoginErrorResponse);
                }

                credentials.Id      = audience.Id;
                audience.DeviceId   = credentials.DeviceId;
                audience.DeviceType = credentials.DeviceType;

                var loginMap = LoginMapper(credentials);
                _accessTokenRepository.UpdateDeviceDetail(loginMap);
                return(TokenMapper(audience, _accessTokenRepository.CreateToken(audience)));
            }
            else if (userByEmail != null)
            {
                if (string.IsNullOrEmpty(userByEmail.Password) && !string.IsNullOrEmpty(userByEmail.AuthId))
                {
                    var facebookUserErrorMessage = new FacebookLoginErrorResponse
                    {
                        Message = "Du är registrerad med Facebook. Försök att logga in med Facebook."
                    };
                    return(facebookUserErrorMessage);
                }
                else
                {
                    throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogilitia inloggningsuppgifter.");
                }
            }
            else
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogilitia inloggningsuppgifter.");
            }
        }