Esempio n. 1
0
        public async Task <JsonResult> IdTokenVerification(string idToken, int clientTimezoneOffset)
        {
            var payload = await GoogleJsonWebSignature.ValidateAsync(idToken,
                                                                     new GoogleJsonWebSignature.ValidationSettings()
            {
                IssuedAtClockTolerance = TimeSpan.FromDays(1)     // for cases when server's time different from UTC time (google time).
            });

            if (payload != null)
            {
                var member = _memberService.GetByEmail(payload.Email);
                if (member != null)
                {
                    FormsAuthentication.SetAuthCookie(member.Username, true);
                    _timezoneOffsetProvider.SetTimezoneOffset(clientTimezoneOffset);

                    if (!_memberServiceHelper.IsFirstLoginPerformed(member))
                    {
                        SendWelcomeNotification(member.Key);
                        _memberServiceHelper.SetFirstLoginPerformed(member);
                    }

                    return(Json(new GoogleAuthResultModel()
                    {
                        Url = DefaultRedirectUrl,
                        Success = true
                    }));
                }
            }
            return(Json(new GoogleAuthResultModel()));
        }
Esempio n. 2
0
        public override ActionResult Login(LoginModelBase model)
        {
            if (!ModelState.IsValid)
            {
                return(View(LoginViewPath, model));
            }

            SetDefaultUserData();

            if (!Membership.ValidateUser(model.Login, model.Password))
            {
                ModelState.AddModelError("UserValidation", _intranetLocalizationService.Translate("Login.Validation.UserNotValid"));
                return(View(LoginViewPath, model));
            }

            var redirectUrl = model.ReturnUrl ?? DefaultRedirectUrl;

            if (Members.Login(model.Login, model.Password))
            {
                _timezoneOffsetProvider.SetTimezoneOffset(model.ClientTimezoneOffset);

                var member = Members.GetByUsername(model.Login);
                if (!_memberServiceHelper.IsFirstLoginPerformed(_memberService.GetByKey(member.GetKey())))
                {
                    SendWelcomeNotification(member.GetKey());
                }
                _memberServiceHelper.SetFirstLoginPerformed(_memberService.GetByKey(member.GetKey()));
            }

            return(Redirect(redirectUrl));
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Login(LoginModelBase loginModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.CollectErrors()));
            }

            var user = await _userManager.FindByEmailAsync(loginModel.Login);

            var login = user != null ? user.UserName : loginModel.Login;

            if (!Membership.ValidateUser(login, loginModel.Password))
            {
                return(BadRequest(_intranetLocalizationService.Translate("credentialsNotValid.lbl")));
            }

            await _authenticationService.LoginAsync(login, loginModel.Password);

            _clientTimezoneProvider.SetClientTimezone(loginModel.ClientTimezoneId);

            var member = _memberService.GetByUsername(login);

            if (!_memberServiceHelper.IsFirstLoginPerformed(member))
            {
                GreetNewMember(member);
            }

            return(Ok());
        }