public ActionResult ChangePassword(string sQuestionAnswer, string NewPassword, string NewPasswordAgain)
        {
            if (sQuestionAnswer == null)
            {
                TempData["Error"] = "Error : Please enter secret answer.";
                return(View("ChangePassword"));
            }
            if (NewPassword != NewPasswordAgain)
            {
                TempData["Error"] = "Error : Passwords does not match.";
                return(View("ChangePassword"));
            }
            TB_USER dbUser = AccountDB.TB_USER.FirstOrDefault(d => d.strAccountID == General.User.strAccountID);

            if (dbUser.sQuestionAnswer != sQuestionAnswer)
            {
                TempData["Error"] = "Error : Answer is wrong.";
                return(View("ChangePassword"));
            }
            dbUser.strPasswd = NewPassword;
            try
            {
                AccountDB.SaveChanges();
                TempData["Information"] = "Password has been updated successfully!";
            }
            catch (Exception)
            {
                TempData["Error"] = "Error : An error occurred";
            }
            return(View("ChangePassword"));
        }
예제 #2
0
        public ActionResult Register(TB_USER User, string repassword, string agree)
        {
            #region Required fills
            if (User.strAccountID == null)
            {
                TempData["Error"] = "Error : AccountID can not be null.";
                return(View(User));
            }
            if (User.strPasswd == null)
            {
                TempData["Error"] = "Error : Password can not be null.";
                return(View(User));
            }
            if (User.strPasswd != repassword)
            {
                TempData["Error"] = "Error : Passwords does not match.";
                return(View(User));
            }
            if (repassword == null)
            {
                TempData["Error"] = "Error : Password confirm can not be null.";
                return(View(User));
            }

            if (User.strEmail == null)
            {
                TempData["Error"] = "Error : Email address can not be null.";
                return(View(User));
            }

            if (User.sQuestionId == 0)
            {
                TempData["Error"] = "Error : Please select Secret Question.";
                return(View(User));
            }
            if (User.sQuestionAnswer == null)
            {
                TempData["Error"] = "Error : Please enter secret question answer.";
                return(View(User));
            }
            if (agree != "Y")
            {
                TempData["Error"] = "Error : You must read and agree our Terms of Service.";
                return(View(User));
            }
            if (!Functions.ValidAccountID(User.strAccountID))
            {
                TempData["Error"] = "Please enter a valid Account ID.";
                return(View(User));
            }
            if (!Functions.ValidAccountID(User.strPasswd))
            {
                TempData["Error"] = "Please enter a valid Password.";
                return(View(User));
            }
            if (!Functions.ValidEmail(User.strEmail))
            {
                TempData["Error"] = "Please enter a valid email address.";
                return(View(User));
            }
            #endregion
            TB_USER accid = AccountDB.TB_USER.FirstOrDefault(d => d.strAccountID == User.strAccountID);
            if (accid != null)
            {
                TempData["Error"] = "Error : This Account ID already in use.";
                return(View(User));
            }
            TB_USER email = AccountDB.TB_USER.FirstOrDefault(d => d.strEmail == User.strEmail);
            if (email != null)
            {
                TempData["Error"] = "Error : This Email already in use.";
                return(View(User));
            }

            TB_USER dbUser = new TB_USER();
            dbUser.strAccountID    = User.strAccountID;
            dbUser.strPasswd       = User.strPasswd;
            dbUser.strSocNo        = "1";
            dbUser.strEmail        = User.strEmail;
            dbUser.strAuthority    = 1;
            dbUser.sQuestionId     = User.sQuestionId;
            dbUser.sQuestionAnswer = User.sQuestionAnswer;
            dbUser.PremiumExpire   = DateTime.Now.AddDays(3);
            dbUser.CountryId       = User.CountryId;
            AccountDB.TB_USER.Add(dbUser);
            try
            {
                TempData["Information"] = "Your account has been created!";
                AccountDB.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
            return(View());
        }