Esempio n. 1
0
        public async Task <JsonResult> IdTokenVerification(string idToken, string clientTimezoneId)
        {
            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);
                    _clientTimezoneProvider.SetClientTimezone(clientTimezoneId);

                    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 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());
        }
        public virtual ActionResult Login(LoginModelBase model)
        {
            if (!ModelState.IsValid)
            {
                return(View(LoginViewPath, model));
            }

            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))
            {
                _clientTimezoneProvider.SetClientTimezone(model.ClientTimezoneId);
            }
            return(Redirect(redirectUrl));
        }