Exemple #1
0
        public ActionResult SignUp(Account model)
        {
            if (ModelState.IsValid)
            {
                var dao = new AccountDao();
                if (dao.CheckUserName(model.Username))
                {
                    ModelState.AddModelError("", "Already taken");
                }
                else if (dao.CheckEmail(model.Email))
                {
                    ModelState.AddModelError("", "This email belongs to another account");
                }
                else
                {
                    var user = new Account();
                    user.Username = model.Username;
                    user.Password = Encryptor.MD5Hash(model.Password);
                    user.Email    = model.Email;

                    var result = dao.Insert(user);
                    if (result != null)
                    {
                        ViewBag.Success = "Đăng ký thành công";
                        model           = new Account();
                        var userd       = dao.GetById(model.Username);
                        var userSession = new UserLogin();
                        userSession.Email    = user.Email;
                        userSession.Username = user.Username;
                        Session.Add(CommonConstants.USER_SESSION, userSession);
                        return(Redirect("/"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Đăng ký không thành công.");
                    }
                }
            }
            return(View(model));
        }