Пример #1
0
 public ActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         user.Creation = DateTime.Now;
         string source = user.Password;
         using (MD5 md5Hash = MD5.Create())
         {
             Encryptor enc = new Encryptor();
             string hash = enc.GetMd5Hash(md5Hash, source);
             if (enc.VerifyMd5Hash(md5Hash, source, hash))
             {
                 user.Password = hash;
                 db.Users.AddObject(user);
                 db.SaveChanges();
                 return RedirectToAction("Index");
             }
             else
             {
                 ViewBag.Status = new SelectList((new UserViewModel()).GetStatus(), "Value", "Text", user.Status);
                 return View(user);
             }
         }
     }
     ViewBag.Status = new SelectList((new UserViewModel()).GetStatus(), "Value", "Text", user.Status);
     return View(user);
 }
Пример #2
0
 private MembershipCreateStatus CreateUser(RegisterModel model)
 {
     if (!db.Users.Where(u => u.Name == model.UserName).Any())
     {
         if (!db.Users.Where(u => u.Email == model.Email).Any())
         {
             User user = new User();
             user.Creation = DateTime.Now;
             string source = model.Password;
             using (MD5 md5Hash = MD5.Create())
             {
                 Encryptor enc = new Encryptor();
                 string hash = enc.GetMd5Hash(md5Hash, source);
                 if (enc.VerifyMd5Hash(md5Hash, source, hash))
                 {
                     user.Name = model.UserName;
                     user.Email = model.Email;
                     user.Password = hash;
                     user.Status = 1;
                     db.Users.AddObject(user);
                     db.SaveChanges();
                     return MembershipCreateStatus.Success;
                 }
                 else
                 {
                     return MembershipCreateStatus.ProviderError;
                 }
             }
         }
         else
         {
             return MembershipCreateStatus.DuplicateEmail;
         }
     }
     else
     {
         return MembershipCreateStatus.DuplicateUserName;
     }
 }
Пример #3
0
        private void FixupUser(User previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.Purchases.Contains(this))
            {
                previousValue.Purchases.Remove(this);
            }

            if (User != null)
            {
                if (!User.Purchases.Contains(this))
                {
                    User.Purchases.Add(this);
                }

                UserID = User.UserID;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("User")
                    && (ChangeTracker.OriginalValues["User"] == User))
                {
                    ChangeTracker.OriginalValues.Remove("User");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("User", previousValue);
                }
                if (User != null && !User.ChangeTracker.ChangeTrackingEnabled)
                {
                    User.StartTracking();
                }
            }
        }
Пример #4
0
 public UserViewModel(User user)
 {
     this.User = user;
     this.Status = user.Status;
 }
Пример #5
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid && user.OldPassword != null)
            {
                User oldUser = db.Users.Single(u => u.UserID == user.UserID);

                string source = user.OldPassword;
                using (MD5 md5Hash = MD5.Create())
                {
                    Encryptor enc = new Encryptor();
                    string hash = enc.GetMd5Hash(md5Hash, source);
                    if (enc.VerifyMd5Hash(md5Hash, source, hash))
                    {
                        if (hash == oldUser.Password)
                        {
                            source = user.Password;
                            hash = enc.GetMd5Hash(md5Hash, source);
                            user.Password = hash;
                            if (enc.VerifyMd5Hash(md5Hash, source, hash))
                            {
                                oldUser.Name = user.Name;
                                oldUser.Email = user.Email;
                                oldUser.Password = hash;
                                oldUser.Status = user.Status;
                                db.Users.Attach(oldUser);
                                db.ObjectStateManager.ChangeObjectState(oldUser, EntityState.Modified);
                                db.SaveChanges();
                                return RedirectToAction("Index");
                            }
                            else
                            {
                                ViewBag.Status = new SelectList((new UserViewModel()).GetStatus(), "Value", "Text", user.Status);
                                return View(user);
                            }
                        }
                        else
                        {
                            ViewBag.Status = new SelectList((new UserViewModel()).GetStatus(), "Value", "Text", user.Status);
                            return View(user);
                        }
                    }
                    else
                    {
                        ViewBag.Status = new SelectList((new UserViewModel()).GetStatus(), "Value", "Text", user.Status);
                        return View(user);
                    }
                }
            }
            ViewBag.Status = new SelectList((new UserViewModel()).GetStatus(), "Value", "Text", user.Status);
            return View(user);
        }