Exemple #1
0
        public ActionResult Registration(Models.AccountModel user)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbEntities())
                {
                    var userNameCheck = db.Users.Where(b => b.UserName == user.UserName);
                    Emailer email = new Emailer();

                    if(userNameCheck.Count()==0)
                    {
                        var crypto = new SimpleCrypto.PBKDF2();

                        var encrpPass = crypto.Compute(user.Password);

                        var sysUser = db.Users.CreateObject();
                        var sysProfile = db.Profiles.CreateObject();

                        sysUser.UserName = user.UserName;
                        sysUser.Password = encrpPass;
                        sysUser.PasswordSalt = crypto.Salt;

                        sysProfile.FirstName = user.FirstName;
                        sysProfile.LastName = user.LastName;
                        sysProfile.Emails = user.Email;
                        sysProfile.CreateDate = DateTime.Today;
                        sysProfile.Phone = user.Phone;

                        db.Profiles.AddObject(sysProfile);
                        db.Users.AddObject(sysUser);

                        db.SaveChanges();
                        //Log user into the site
                        email.RegistrationEmail(user.UserName, user.Email);
                        Login(user.UserName, user.Password);
                        return RedirectToAction("SuccessfulReg", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Username already exist.");
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Register Data is incorrect.");
            }
            return View();
        }
Exemple #2
0
        public ActionResult PasswordRetrieval(Models.PasswordRetrievalModel pr)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbEntities())
                {
                    var crypto = new SimpleCrypto.PBKDF2();
                    if (pr.ConfirmEmail.Equals(pr.Email))
                    {
                        int start = 100000; int end = 900000; int rand;
                        User sysUser = db.Users.FirstOrDefault(m => m.UserName == pr.UserName);
                        Random rnd = new Random();
                        rand = rnd.Next(start, end);
                        sysUser.Password = crypto.Compute(rand.ToString());
                        sysUser.PasswordSalt = crypto.Salt;
                        db.SaveChanges();

                        Emailer email = new Emailer();
                        email.ChangePasswordEmail(pr.UserName, pr.Email, rand.ToString());
                    }
                    return RedirectToAction("PasswordChangeOk", "Account");
                }
            }

            return View();
        }