コード例 #1
0
        public ActionResult Register(User user, string password)
        {
            UserAuthDb db = new UserAuthDb(Properties.Settings.Default.ConStr);

            db.AddUser(user, password);
            return(Redirect("/"));
        }
コード例 #2
0
        public ActionResult Reset(string password, string token)
        {
            var db = new UserAuthDb(Properties.Settings.Default.ConStr);

            db.ResetPassword(token, password);
            return(Redirect("/home/login"));
        }
コード例 #3
0
        public ActionResult ForgotPassword(string email)
        {
            var db       = new UserAuthDb(Properties.Settings.Default.ConStr);
            var userGuid = db.AddForgottenPassword(email);

            EmailSender.SendEmail(email, userGuid.User.FirstName, "Reset Password", "http://localhost:53464/home/reset?token=" + userGuid.Guid);
            return(View("ForgotPasswordSent"));
        }
コード例 #4
0
        public ActionResult Secret()
        {
            UserAuthDb db   = new UserAuthDb(Properties.Settings.Default.ConStr);
            User       user = db.GetByEmail(User.Identity.Name);

            return(View(new SecretPageViewModel {
                User = user
            }));
        }
コード例 #5
0
        public ActionResult Secret()
        {
            bool   isLoggedIn = User.Identity.IsAuthenticated; // true/false if user is logged in
            string email      = User.Identity.Name;            //will always match the first argument in SetAuthCookie
            var    db         = new UserAuthDb(Properties.Settings.Default.ConStr);
            User   user       = db.GetByEmail(email);

            return(View(new SecretPageViewModel {
                User = user
            }));
        }
コード例 #6
0
        public ActionResult Login(string email, string password)
        {
            var db   = new UserAuthDb(Properties.Settings.Default.ConStr);
            var user = db.Login(email, password);

            if (user == null)
            {
                return(Redirect("/home/login"));
            }
            FormsAuthentication.SetAuthCookie(email, true);
            return(Redirect("/home/secret"));
        }
コード例 #7
0
        public ActionResult Reset(string token)
        {
            var db = new UserAuthDb(Properties.Settings.Default.ConStr);
            var forgottenPassword = db.GetForgottenPassword(token);

            if (forgottenPassword == null)
            {
                return(Redirect("/"));
            }

            if (forgottenPassword.Timestamp.AddMinutes(30) < DateTime.Now)
            {
                return(View("Expired"));
            }

            return(View(new ResetViewModel {
                Guid = forgottenPassword.Guid
            }));
        }