Пример #1
0
        public LoginModule(IThumbsUpNancyApi thumbsUp)
        {
            Get["/login"] = _ =>
            {
                if (Request.Query.error.HasValue)
                {
                    ViewBag.HasError = true;
                    ViewBag.ErrorMessage = thumbsUp.GetErrorMessage((int)Request.Query.errorcode);
                }
                return View["login"];
            };

            Post["/login"] = _ =>
            {
                var result = thumbsUp.ValidateUser((string)this.Request.Form.Username, (string)this.Request.Form.Password);
                if (result.Success) return this.LoginAndRedirect(result.Data.ThumbKey.Value);
                return ProcessError(result);
            };

            Get["/sso/{thumbkey}"] = url =>
            {
                Guid thumbKey = new Guid(url.thumbkey);
                var result = thumbsUp.ValidateKey(thumbKey);
                if (result.Success) return this.LoginAndRedirect(thumbKey);
                return ProcessError(result);
            };
        }
Пример #2
0
        public UserModule(IThumbsUpNancyApi thumbsUp)
            : base("/user")
        {
            this.RequiresAuthentication();

            Post["/create"] = _ => Response.AsJson(thumbsUp.CreateUser(Params.UserName, Params.Email).Data);
        }
Пример #3
0
        public MainModule(IThumbsUpNancyApi thumbsUp)
        {
            this.RequiresAuthentication();

            Get["/patches"] = _ =>
            {
                ViewBag.AllPatches = PatchService.GetAllPatches();
                return View["patches"];
            };

            Get["/logout"] = _ =>
            {
                var thumbKey = ((ThumbsUpNancyUser)Context.CurrentUser).ThumbKey;
                thumbsUp.Logout(thumbKey);
                return this.LogoutAndRedirect("~/");
            };
        }
Пример #4
0
        public LoginModule(IThumbsUpNancyApi thumbsUp)
        {
            Get["/login"] = _ =>
            {
                return View["loginView"];
            };

            Get["/logout"] = url =>
            {
                var user = Context.CurrentUser as ThumbsUpNancyUser;
                if (user != null) thumbsUp.Logout(user.ThumbKey);
                return this.LogoutAndRedirect("~/");
            };

            Post["/login"] = _ =>
            {
                var result = thumbsUp.ValidateUser(Params.UserName, Params.Password);
                if (result.Success) return this.LoginAndRedirect(result.Data.ThumbKey.Value);

                SetMessageError(result.GetMessage());
                return View["loginView"];
            };

            Get["/password-request"] = _ =>
            {
                return View["PasswordRequestView"];
            };

            Post["/password-request"] = _ =>
            {
                var result = thumbsUp.ForgotPasswordRequest(Params.UserName, Params.Email);
                if (result.Success)
                {
                    var token = result.Data.Token;
                    var body = "To complete the new password request please click on the following link : " + Request.Url.SiteBase + "/password-generate/" + token;
                    var sendResult = Gmail.Send(Params.Email, "ThumbsUp - Nancy Demo : New Password Request", body);
                    var success = sendResult.Item1;
                    if (success)
                    {
                        SetMessageSuccess("Success. Please check your email for further instructions.");
                    }
                    else
                    {
                        SetMessageError(sendResult.Item2);
                    }
                }
                else
                {
                    SetMessageError(result.GetMessage());
                }
                return View["PasswordRequestView"];
            };

            Get["/password-generate/{token}"] = _ =>
            {
                return View["PasswordGenerateView"];
            };

            Post["/password-generate/{token}"] = _ =>
            {
                var result = thumbsUp.ForgotPasswordReset(Params.UserName, Params.Token);
                if (result.Success)
                {
                    SetMessageSuccess("Success. Your new password is shown below");
                    ViewBag.NewPassword = result.Data.Password;
                }
                else
                {
                    SetMessageError(result.GetMessage());
                }
                return View["PasswordGenerateView"];
            };
        }