示例#1
0
        public ActionResult Register(Models.User user)
        {
            if (ModelState.IsValid)
            {
                if (user.Registration(user))
                {
                    string subject = "Matcha Registration";

                    System.Diagnostics.Debug.WriteLine(user.Token);
                    string body = "Please follow this link to verify your account http://" +
                                  Request.Url.Authority + "/User/VerifyAccount?token=" + user.Token +
                                  "&username="******"user"] = user;
                        return(RedirectToAction("EmailSent", "User"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Failed to register. Please try again");
                }
            }
            return(View(user));
        }
示例#2
0
        public ActionResult Login(Models.User user)
        {
            if (ModelState.IsValid)
            {
                if (user.IsValid(user.Username, user.Password))
                {
                    Session["LoggedIn"] = true;
                    Session["Username"] = user.Username;
                    Session["Token"]    = user.Token;

                    FormsAuthentication.SetAuthCookie(user.Username, true);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    if (Session["Usertoken"] != null)
                    {
                        System.Diagnostics.Debug.WriteLine("USER TOKEN " + Session["Usertoken"].ToString());

                        user = user.getUserInfo(user.Username);

                        string body = "Please follow this link to verify your account http://" +
                                      Request.Url.Authority + "/User/VerifyAccount?token=" +
                                      user.Token + "&username="******"Matcha Registration";

                        var  sendMail = new Models.SendMail.SendMail();
                        bool sent     = sendMail.SendEmail(user.Email, subject, body);
                        ModelState.AddModelError("", "Account has not yet been verified. Please check your mail");
                        //if (sent)
                        //{
                        //    TempData["user"] = user;
                        //    ModelState.AddModelError("", "Account has not yet been verified. Please check your mail");
                        //    return RedirectToAction("EmailSent", "User");
                        //}
                        //else
                        //{
                        //    ModelState.AddModelError("", "Failed to resend the message. I dont know why");
                        //    return RedirectToAction("Index", "Home");
                        //}
                    }
                    else
                    {
                        ModelState.AddModelError("", "Failed to login. Please try again");
                    }
                }
            }
            return(View(user));
        }