Esempio n. 1
0
        public LoginModule(ISaltedHash saltedHash, CloudTable <User> users)
            : base("/account/login")
        {
            _saltedHash = saltedHash;
            _users      = users;

            Get["/"] = x =>
            {
                if (IsAuthenticated)
                {
                    return(this.AsRedirectQueryStringOrDefault("~/dashboard"));
                }

                this.CreateNewCsrfToken();

                var model = this.Bind <LoginModel>();
                return(View["account/login", model]);
            };

            Post["/"] = x =>
            {
                if (IsAuthenticated)
                {
                    return(this.AsRedirectQueryStringOrDefault("~/dashboard"));
                }

                this.ValidateCsrfToken();

                var model = this.BindAndValidate <LoginModel>();
                if (!ModelValidationResult.IsValid)
                {
                    return(View["account/login", model]);
                }

                var user = VerifyUser(model);
                if (user == null)
                {
                    return(InvalidLogin(model));
                }

                // TODO: Publish event for CQRS/ES audit logging
                return(this.SignIn(user, model.RememberMe));
            };
        }
Esempio n. 2
0
        public LoginModule(ISaltedHash saltedHash, CloudTable<User> users)
            : base("/account/login")
        {
            _saltedHash = saltedHash;
            _users = users;

            Get["/"] = x =>
            {
                if (IsAuthenticated)
                    return this.AsRedirectQueryStringOrDefault("~/dashboard");

                this.CreateNewCsrfToken();

                var model = this.Bind<LoginModel>();
                return View["account/login", model];
            };

            Post["/"] = x =>
            {
                if (IsAuthenticated)
                    return this.AsRedirectQueryStringOrDefault("~/dashboard");

                this.ValidateCsrfToken();

                var model = this.BindAndValidate<LoginModel>();
                if (!ModelValidationResult.IsValid)
                    return View["account/login", model];

                var user = VerifyUser(model);
                if (user == null)
                    return InvalidLogin(model);

                // TODO: Publish event for CQRS/ES audit logging
                return this.SignIn(user, model.RememberMe);
            };
        }