Exemplo n.º 1
0
        public ActionResult ActivateAccount2(MultipleModel.AuthModelVM request)
        {
            if (ModelState.IsValid)
            {
                using (var db = new LibraryDbContext())
                {
                    MultipleModel.AuthModelVM vm = new MultipleModel.AuthModelVM();
                    vm.UserModel = db.Users.SingleOrDefault(u => u.Id == request.UserModel.Id);
                    var crypto     = new SimpleCrypto.PBKDF2();
                    var encrypPass = crypto.Compute(request.ActivationModel1.Password);

                    vm.UserModel.PasswordSalt   = crypto.Salt;
                    vm.UserModel.Password       = encrypPass;
                    vm.UserModel.SecretQuestion = request.ActivationModel1.SecretQuestion;
                    vm.UserModel.SecretAnswer   = request.ActivationModel1.SecretAnswer;
                    vm.UserModel.Status         = true;
                    vm.UserModel.Deleted        = false;
                    vm.UserModel.UpdatedAt      = DateTime.UtcNow;

                    vm.UserModel.Student.Birthday       = request.ActivationModel1.Birthday;
                    vm.UserModel.Student.StudentAddress = new LibraryDbContext.StudentAddressModel
                    {
                        ZipCode  = request.ActivationModel1.ZipCode, Address1 = request.ActivationModel1.Address1,
                        Address2 = request.ActivationModel1.Address2, City = request.ActivationModel1.City,
                        Country  = request.ActivationModel1.Country, CreatedAt = DateTime.UtcNow,
                    };
                    db.Entry(vm.UserModel).State = EntityState.Modified;
                    db.SaveChanges();

                    var ctx         = Request.GetOwinContext();
                    var authManager = ctx.Authentication;
                    authManager.SignOut("ApplicationCookie");

                    var loginVM = new MultipleModel.LoginModelVM();
                    loginVM.Error = false;
                    var    errorList = new List <string>();
                    string message   = "You have successfully activated your account. Please log in";
                    errorList.Add(message);
                    loginVM.Message     = errorList;
                    TempData["LoginTD"] = loginVM;

                    return(RedirectToAction("Login"));
                }
            }
            request.Error              = true;
            request.Message            = CustomValidationMessage.GetErrorList(ViewData.ModelState);
            TempData["UserActivation"] = request;
            return(RedirectToAction("ActivateAccount2", new { id = request.UserModel.Id }));
        }
Exemplo n.º 2
0
        public ActionResult ActivateAccount2(Guid?id)
        {
            if (id.HasValue)
            {
                var db = new LibraryDbContext();
                MultipleModel.AuthModelVM vm = new MultipleModel.AuthModelVM();
                var userActivation           = TempData["UserActivation"] as MultipleModel.AuthModelVM;

                if (userActivation != null)
                {
                    vm = userActivation;
                }

                vm.UserModel = db.Users.Where(u => u.Id == id && u.Deleted == false).SingleOrDefault();
                return(View(vm));
            }

            return(RedirectToAction("Login"));
        }