public override bool IsUserInRole(string username, string roleName)
 {
     if (string.IsNullOrEmpty(username))
     {
         return false;
     }
     if (string.IsNullOrEmpty(roleName))
     {
         return false;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.UserName == username);
         if (User == null)
         {
             return false;
         }
         Role Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (Role == null)
         {
             return false;
         }
         return User.Roles.Contains(Role);
     }
 }
 public override string[] GetAllRoles()
 {
     using (PMToolContext Context = new PMToolContext())
     {
         return Context.Roles.Select(Rl => Rl.RoleName).ToArray();
     }
 }
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     if (string.IsNullOrEmpty(roleName))
         {
             return false;
         }
         using (PMToolContext Context = new PMToolContext())
         {
             Role Role = null;
             Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
             if (Role == null)
             {
                 return false;
             }
             if (throwOnPopulatedRole)
             {
                 if (Role.Users.Any())
                 {
                     return false;
                 }
             }
             else
             {
                 Role.Users.Clear();
             }
             Context.Roles.Remove(Role);
             Context.SaveChanges();
             return true;
         }
 }
Exemple #4
0
 public static void Register()
 {
     PMToolContext context = new PMToolContext();
     context.Database.Initialize(true);
     if (!WebMatrix.WebData.WebSecurity.Initialized)
         WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection("PMToolContext",
             "UserProfile", "UserId", "UserName", autoCreateTables: true);
 }
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     using (PMToolContext Context = new PMToolContext())
         {
             List<User> Users = Context.Users.Where(Usr => usernames.Contains(Usr.Username)).ToList();
             List<Role> Roles = Context.Roles.Where(Rl => roleNames.Contains(Rl.RoleName)).ToList();
             foreach (User user in Users)
             {
                 foreach (Role role in Roles)
                 {
                     if (!user.Roles.Contains(role))
                     {
                         user.Roles.Add(role);
                     }
                 }
             }
             Context.SaveChanges();
         }
 }
 public override bool RoleExists(string roleName)
 {
     if (string.IsNullOrEmpty(roleName))
     {
         return false;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         Role Role = null;
         Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (Role != null)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 }
 public override string[] GetUsersInRole(string roleName)
 {
     if (string.IsNullOrEmpty(roleName))
     {
         return null;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         Role Role = null;
         Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (Role != null)
         {
             return Role.Users.Select(Usr => Usr.UserName).ToArray();
         }
         else
         {
             return null;
         }
     }
 }
 public override void CreateRole(string roleName)
 {
     if (!string.IsNullOrEmpty(roleName))
         {
             using (PMToolContext Context = new PMToolContext())
             {
                 Role Role = null;
                 Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
                 if (Role == null)
                 {
                     Role NewRole = new Role
                     {
                         RoleId = Guid.NewGuid(),
                         RoleName = roleName
                     };
                     Context.Roles.Add(NewRole);
                     Context.SaveChanges();
                 }
             }
         }
 }
            public SimpleMembershipInitializer()
            {
                //   Database.SetInitializer<UsersContext>(null);

                try
                {
                    using (var context = new PMToolContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
 public TimeLogRepository(PMToolContext context)
 {
     this.context = context;
 }
 public NotificationRepository(PMToolContext context)
 {
     this.context = context;
 }
        public EmailSentStatusRepository(PMToolContext context)
        {

            this.context = context;
        }
Exemple #13
0
 public EmailSentStatusRepository(PMToolContext context)
 {
     this.context = context;
 }
Exemple #14
0
        public TaskRepository(PMToolContext context)
        {

            this.context = context;
        }
Exemple #15
0
 public TaskMessageRepository(PMToolContext context)
 {
     this.context = context;
 }
Exemple #16
0
 public LabelRepository(PMToolContext context)
 {
     this.context = context;
 }
Exemple #17
0
 public ProjectRepository(PMToolContext context)
 {
     this.context = context;
 }
Exemple #18
0
 public UserRepository(PMToolContext _context)
 {
     this.context = _context;
 }
Exemple #19
0
 public EmailSchedulerRepository(PMToolContext context)
 {
     this.context = context;
 }
 public CommentRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
 {
     using (PMToolContext Context = new PMToolContext())
     {
         foreach (String username in usernames)
         {
             String us = username;
             UserProfile user = Context.UserProfiles.FirstOrDefault(U => U.UserName == us);
             if (user != null)
             {
                 foreach (String roleName in roleNames)
                 {
                     String rl = roleName;
                     Role role = user.Roles.FirstOrDefault(R => R.RoleName == rl);
                     if (role != null)
                     {
                         user.Roles.Remove(role);
                     }
                 }
             }
         }
         Context.SaveChanges();
     }
 }
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            if (string.IsNullOrEmpty(roleName))
            {
                return null;
            }

            if (string.IsNullOrEmpty(usernameToMatch))
            {
                return null;
            }

            using (PMToolContext Context = new PMToolContext())
            {

                return (from Rl in Context.Roles from Usr in Rl.Users where Rl.RoleName == roleName && Usr.UserName.Contains(usernameToMatch) select Usr.Username).ToArray();
            }
        }
 public ProjectStatusRuleRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override bool ValidateUser(string username, string password)
 {
     if (string.IsNullOrEmpty(username))
     {
         return false;
     }
     if (string.IsNullOrEmpty(password))
     {
         return false;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.Username == username);
         if (User == null)
         {
             return false;
         }
         //if (!User.IsApproved)
         //{
         //    return false;
         //}
         //if (User.IsLockedOut)
         //{
         //    return false;
         //}
         String HashedPassword = User.Password;
         Boolean VerificationSucceeded = (HashedPassword != null && Crypto.VerifyHashedPassword(HashedPassword, password));
         if (VerificationSucceeded)
         {
             User.PasswordFailuresSinceLastSuccess = 0;
             User.LastLoginDate = DateTime.UtcNow;
             User.LastActivityDate = DateTime.UtcNow;
         }
         else
         {
             int Failures = User.PasswordFailuresSinceLastSuccess;
             if (Failures < MaxInvalidPasswordAttempts)
             {
                 User.PasswordFailuresSinceLastSuccess += 1;
                 User.LastPasswordFailureDate = DateTime.UtcNow;
             }
             else if (Failures >= MaxInvalidPasswordAttempts)
             {
                 User.LastPasswordFailureDate = DateTime.UtcNow;
                 User.LastLockoutDate = DateTime.UtcNow;
                 User.IsLockedOut = true;
             }
         }
         Context.SaveChanges();
         if (VerificationSucceeded)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 }
        public TimeLogRepository(PMToolContext context)
        {

            this.context = context;
        }
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            if (providerUserKey is Guid) { }
            else
            {
                return null;
            }

            using (PMToolContext Context = new PMToolContext())
            {
                UserProfile User = null;
                User = Context.UserProfiles.Find(providerUserKey);
                if (User != null)
                {
                    if (userIsOnline)
                    {
                        User.LastActivityDate = DateTime.UtcNow;
                        Context.SaveChanges();
                    }
                    return new MembershipUser(Membership.Provider.Name, User.UserName, User.UserId, User.Email, null, null, User.IsApproved, User.IsLockedOut, User.CreateDate.Value, User.LastLoginDate.Value, User.LastActivityDate.Value, User.LastPasswordChangedDate.Value, User.LastLockoutDate.Value);
                }
                else
                {
                    return null;
                }
            }
        }
 public CommentRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override bool UnlockUser(string userName)
 {
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.Username == userName);
         if (User != null)
         {
             User.IsLockedOut = false;
             User.PasswordFailuresSinceLastSuccess = 0;
             Context.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Exemple #29
0
 public ProjectRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override bool DeleteUser(string username, bool deleteAllRelatedData)
 {
     if (string.IsNullOrEmpty(username))
     {
         return false;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.UserName == username);
         if (User != null)
         {
             Context.UserProfiles.Remove(User);
             Context.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Exemple #31
0
  public UserRepository(PMToolContext _context)
 {
     
     this.context = _context;
 }
 public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
 {
     MembershipUserCollection MembershipUsers = new MembershipUserCollection();
     using (PMToolContext Context = new PMToolContext())
     {
         totalRecords = Context.UserProfiles.Count();
         IQueryable<UserProfile> Users = Context.UserProfiles.OrderBy(Usrn => Usrn.UserName).Skip(pageIndex * pageSize).Take(pageSize);
         foreach (UserProfile user in Users)
         {
             MembershipUsers.Add(new MembershipUser(Membership.Provider.Name, user.UserName, user.UserId, user.Email, null, null, user.IsApproved, user.IsLockedOut, user.CreateDate.Value, user.LastLoginDate.Value, user.LastActivityDate.Value, user.LastPasswordChangedDate.Value, user.LastLockoutDate.Value));
         }
     }
     return MembershipUsers;
 }
   public TaskActivityLogRepository(PMToolContext context)
 {
     
     this.context = context;
 }
Exemple #34
0
 public TaskActivityLogRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     if (string.IsNullOrEmpty(username))
     {
         return null;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.UserName == username);
         if (User != null)
         {
             if (userIsOnline)
             {
                 //User.LastActivityDate = DateTime.UtcNow;
                 Context.SaveChanges();
             }
             return new MembershipUser(Membership.Provider.Name, User.UserName, User.UserId, User.Email, null, null, User.IsApproved, User.IsLockedOut, User.CreateDate.Value, User.LastLoginDate.Value, User.LastActivityDate.Value, User.LastPasswordChangedDate.Value, User.LastLockoutDate.Value);
         }
         else
         {
             return null;
         }
     }
 }
 public PriorityRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override bool ChangePassword(string username, string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(username))
     {
         return false;
     }
     if (string.IsNullOrEmpty(oldPassword))
     {
         return false;
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         return false;
     }
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.UserName == username);
         if (User == null)
         {
             return false;
         }
         String HashedPassword = User.Password;
         Boolean VerificationSucceeded = (HashedPassword != null && Crypto.VerifyHashedPassword(HashedPassword, oldPassword));
         if (VerificationSucceeded)
         {
             User.PasswordFailuresSinceLastSuccess = 0;
         }
         else
         {
             int Failures = User.PasswordFailuresSinceLastSuccess;
             if (Failures < MaxInvalidPasswordAttempts)
             {
                 User.PasswordFailuresSinceLastSuccess += 1;
                 User.LastPasswordFailureDate = DateTime.UtcNow;
             }
             else if (Failures >= MaxInvalidPasswordAttempts)
             {
                 User.LastPasswordFailureDate = DateTime.UtcNow;
                 User.LastLockoutDate = DateTime.UtcNow;
                 User.IsLockedOut = true;
             }
             Context.SaveChanges();
             return false;
         }
         String NewHashedPassword = Crypto.HashPassword(newPassword);
         if (NewHashedPassword.Length > 128)
         {
             return false;
         }
         User.Password = NewHashedPassword;
         User.LastPasswordChangedDate = DateTime.UtcNow;
         Context.SaveChanges();
         return true;
     }
 }
 public NotificationRepository(PMToolContext context)
 {
     this.context = context;
 }
 public override int GetNumberOfUsersOnline()
 {
     DateTime DateActive = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(Convert.ToDouble(Membership.UserIsOnlineTimeWindow)));
     using (PMToolContext Context = new PMToolContext())
     {
         return Context.UserProfiles.Where(Usr => Usr.LastActivityDate > DateActive).Count();
     }
 }
Exemple #40
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (PMToolContext db = new PMToolContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
 public override string GetUserNameByEmail(string email)
 {
     using (PMToolContext Context = new PMToolContext())
     {
         UserProfile User = null;
         User = Context.UserProfiles.FirstOrDefault(Usr => Usr.Email == email);
         if (User != null)
         {
             return User.UserName;
         }
         else
         {
             return string.Empty;
         }
     }
 }
 public UnitOfWork()
 {
     context = new PMToolContext();
 }
        public string CreateAccount(string userName, string password, bool requireConfirmationToken)
        {

            if (string.IsNullOrEmpty(userName))
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName);
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
            }

            string hashedPassword = Crypto.HashPassword(password);
            if (hashedPassword.Length > 128)
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
            }

            using (PMToolContext Context = new PMToolContext())
            {
                if (Context.UserProfiles.Where(Usr => Usr.UserName == userName).Any())
                {
                    throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
                }

                string token = string.Empty;
                if (requireConfirmationToken)
                {
                    token = GenerateToken();
                }

                UserProfile NewUser = new UserProfile
                {
                    //UserId = Guid.NewGuid(),
                    UserName = userName,
                    //Password = hashedPassword,        
                    //IsApproved = !requireConfirmationToken,
                    Email = string.Empty,
                    //CreateDate = DateTime.UtcNow,
                    //LastPasswordChangedDate = DateTime.UtcNow,
                    //PasswordFailuresSinceLastSuccess = 0,
                    //LastLoginDate = DateTime.UtcNow,
                    //LastActivityDate = DateTime.UtcNow,
                    //LastLockoutDate = DateTime.UtcNow,
                    //IsLockedOut = false,
                    //LastPasswordFailureDate = DateTime.UtcNow,
                    //ConfirmationToken = token 
                };

                Context.UserProfiles.Add(NewUser);
                Context.SaveChanges();
                return token;
            }
         
        }
 public UnitOfWork(PMToolContext _context)
 {
     this.context = _context;
 }