Ejemplo n.º 1
0
 /// <summary>
 /// Sprawdza czy hasło i użytkownik się zgadzają
 /// </summary>
 /// <param name="username">Nazwa użytkownika</param>
 /// <param name="password">Hasło użytkownika</param>
 /// <returns>Prawda jeżeli wszystko się zgadza</returns>
 public override bool ValidateUser(string username, string password)
 {
     DiamondsEntities db = new DiamondsEntities();
     User user = db.Users.FirstOrDefault(u => u.email == username);
     if (user != null && user.checkPassword(password))
     {
         user.lastLoginDate = DateTime.Now;
         db.SaveChanges();
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            DiamondsEntities db = new DiamondsEntities();
            User user = db.Users.FirstOrDefault(u => u.email == username || u.name == username);
            if (!user.checkPassword(oldPassword))
                return false;
            else
            {
                user.setPassword(newPassword);
                db.SaveChanges();
            }

            return true;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Tworzy użytkownika
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="passwordQuestion"></param>
        /// <param name="passwordAnswer"></param>
        /// <param name="isApproved"></param>
        /// <param name="providerUserKey"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser user = GetUser(username, true);

            if (user == null)
            {
                DiamondsEntities db = new DiamondsEntities();

                User newUser = new User();
                newUser.name = username;
                newUser.setPassword(password);
                newUser.email = email;
                newUser.createDate = newUser.lastLoginDate = DateTime.Now;
                newUser.isConfirmed = isApproved;

                db.Users.Add(newUser);
                db.SaveChanges();

                status = MembershipCreateStatus.Success;

                return GetUser(username, true);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
Ejemplo n.º 4
0
        public ActionResult RoleEdit(int id, Role role, List<RoleAccess> roleAccesses)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Attach(role);
                db.Entry(role).State = EntityState.Modified;
                db.SaveChanges();

                db = new DiamondsEntities();
                role = db.Roles.Single(r => r.roleId == id);

                role.rolegroup_role.Clear();
                foreach (var group in roleAccesses)
                    role.rolegroup_role.Add(group.ToRoleGroupRole());
                db.SaveChanges();
                return RedirectToAction("RoleEdit", new { id = role.roleId });
            }

            ViewBag.RoleAccess = getGroupsAccess(role);
            return View(role);
        }