Exemplo n.º 1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (RaisingCombatDBEntities dc = new RaisingCombatDBEntities())
                {
                    var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password = Crypto.Hash(model.NewPassword);
                        // reset password code is set to empty as can only be used once
                        user.ResetPasswordCode = "";
                        // to stop confirm password issue
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New Password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something is invalid";
            }

            ViewBag.Message = message;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult ForgotPassword(string EmailID)
        {
            //Verify Emial ID
            string message = "";
            bool   status  = false;

            using (RaisingCombatDBEntities dc = new RaisingCombatDBEntities())
            {
                var account = dc.Users.Where(a => a.EmailID == EmailID).FirstOrDefault();
                if (account != null)
                {
                    // Send email for reset password and generate reset password link then send email
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.EmailID, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;
                    //This line is to avoid confirm password not match issue - as confirm password property added in current model class
                    dc.Configuration.ValidateOnSaveEnabled = false;
                    //Update Database
                    dc.SaveChanges();
                    message = "Reset Password link has been sent to your email address";
                }
                else
                {
                    message = "Account does not exist. Please register!";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                //Email is already Exist
                #region //Email is already Exit
                var isExist = IsEmailExist(user.EmailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion

                #region //Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region //Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion

                user.IsEmailVerified = false;

                #region Save to Database
                using (RaisingCombatDBEntities dc = new RaisingCombatDBEntities())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

                    //Send Email to User
                    SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString());
                    message = "Registration successfully done. Account activation link " +
                              "has been sent to your email id: " + user.EmailID;
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Exemplo n.º 4
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (RaisingCombatDBEntities dc = new RaisingCombatDBEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false; // This line is to avoid confirm password does not match issue on save changes
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }