示例#1
0
 public override bool ChangePassword(string userName, string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(userName))
     {
         throw CreateArgumentNullOrEmptyException("userName");
     }
     if (string.IsNullOrEmpty(oldPassword))
     {
         throw CreateArgumentNullOrEmptyException("oldPassword");
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         throw CreateArgumentNullOrEmptyException("newPassword");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
         if (user == null)
         {
             return(false);
         }
         dynamic hashedPassword        = user.Password;
         bool    verificationSucceeded = (hashedPassword != null && CodeFirstCrypto.VerifyHashedPassword(hashedPassword, oldPassword));
         if (verificationSucceeded)
         {
             user.PasswordFailuresSinceLastSuccess = 0;
         }
         else
         {
             int failures = user.PasswordFailuresSinceLastSuccess;
             if (failures != -1)
             {
                 user.PasswordFailuresSinceLastSuccess += 1;
                 user.LastPasswordFailureDate           = DateTime.UtcNow;
             }
             context.SaveChanges();
             return(false);
         }
         dynamic newhashedPassword = CodeFirstCrypto.HashPassword(newPassword);
         if (newhashedPassword.Length > 128)
         {
             throw new ArgumentException("Password too long");
         }
         user.Password            = newhashedPassword;
         user.PasswordChangedDate = DateTime.UtcNow;
         context.SaveChanges();
         return(true);
     }
 }
        public ActionResult Assign(FormCollection col)
        {
            int enquiryId = Convert.ToInt32(col.GetValue("Enquiry").AttemptedValue);
            int projectId = Convert.ToInt32(col.GetValue("Project").AttemptedValue);
            int TeamType = Convert.ToInt32(col.GetValue("TeamType").AttemptedValue);
            string TeamTypeName = (TeamType==1)?"Non Kenwood Team":"Kenwood Team";
            string TeamName = String.Empty;
            if(TeamType==1)
            {
                TeamName = col.GetValue("Non_Kenwood").AttemptedValue.ToString();

            }
            else{

                 TeamName = teamRepository.Find(Convert.ToInt32(col.GetValue("Team").AttemptedValue)).TeamName;
            }
            TeamProject team = new TeamProject();
            team.ProjectID = projectId;
            team.TeamID = Convert.ToInt32(col.GetValue("Team").AttemptedValue);
            BusinessFlowContext context = new BusinessFlowContext();
            context.TeamProjects.Add(team);
            context.SaveChanges();

            return RedirectToAction("TeamAssigned",team);
        }
示例#3
0
 public override bool ResetPasswordWithToken(string token, string newPassword)
 {
     if (string.IsNullOrEmpty(newPassword))
     {
         throw CreateArgumentNullOrEmptyException("newPassword");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic user = context.User.FirstOrDefault(Usr => Usr.PasswordVerificationToken == token && Usr.PasswordVerificationTokenExpirationDate > DateTime.UtcNow);
         if (user != null)
         {
             dynamic newhashedPassword = CodeFirstCrypto.HashPassword(newPassword);
             if (newhashedPassword.Length > 128)
             {
                 throw new ArgumentException("Password too long");
             }
             user.Password                  = newhashedPassword;
             user.PasswordChangedDate       = DateTime.UtcNow;
             user.PasswordVerificationToken = null;
             user.PasswordVerificationTokenExpirationDate = null;
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     if (string.IsNullOrEmpty(roleName))
     {
         throw CreateArgumentNullOrEmptyException("roleName");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (role == null)
         {
             throw new InvalidOperationException("Role not found");
         }
         if (throwOnPopulatedRole)
         {
             dynamic usersInRole = role.Users.Any;
             if (usersInRole)
             {
                 throw new InvalidOperationException(string.Format("Role populated: {0}", roleName));
             }
         }
         else
         {
             foreach (User usr_loopVariable in role.Users)
             {
                 var usr = usr_loopVariable;
                 context.User.Remove(usr);
             }
         }
         context.Roles.Remove(role);
         context.SaveChanges();
         return(true);
     }
 }
示例#5
0
 public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
 {
     if (string.IsNullOrEmpty(userName))
     {
         throw CreateArgumentNullOrEmptyException("userName");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
         if (user == null)
         {
             throw new InvalidOperationException(string.Format("User not found: {0}", userName));
         }
         if (!user.IsConfirmed)
         {
             throw new InvalidOperationException(string.Format("User not found: {0}", userName));
         }
         string token = null;
         if (user.PasswordVerificationTokenExpirationDate > DateTime.UtcNow)
         {
             token = user.PasswordVerificationToken;
         }
         else
         {
             token = CodeFirstCrypto.GenerateToken();
         }
         user.PasswordVerificationToken = token;
         user.PasswordVerificationTokenExpirationDate = DateTime.UtcNow.AddMinutes(tokenExpirationInMinutesFromNow);
         context.SaveChanges();
         return(token);
     }
 }
 public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
 {
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         foreach (string username_loopVariable in usernames)
         {
             var    username = username_loopVariable;
             string us       = username;
             User   user     = context.User.FirstOrDefault(u => u.Username == us);
             if (user != null)
             {
                 foreach (string rolename_loopVariable in roleNames)
                 {
                     var  rolename = rolename_loopVariable;
                     var  rl       = rolename;
                     Role role     = user.Roles.FirstOrDefault(r => r.RoleName == rl);
                     if (role != null)
                     {
                         user.Roles.Remove(role);
                     }
                 }
             }
         }
         context.SaveChanges();
     }
 }
示例#7
0
        public void Save()
        {
            try
            {
                context.SaveChanges();
            }

            catch (Exception e)
            {
            }
        }
示例#8
0
 public override bool ExtendedValidateUser(string userNameOrEmail, string password)
 {
     if (string.IsNullOrEmpty(userNameOrEmail))
     {
         throw CreateArgumentNullOrEmptyException("userNameOrEmail");
     }
     if (string.IsNullOrEmpty(password))
     {
         throw CreateArgumentNullOrEmptyException("password");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         User user = null;
         user = context.User.FirstOrDefault(Usr => Usr.Username == userNameOrEmail);
         if (user == null)
         {
             user = context.User.FirstOrDefault(Usr => Usr.Email == userNameOrEmail);
         }
         if (user == null)
         {
             return(false);
         }
         if (!user.IsConfirmed)
         {
             return(false);
         }
         dynamic hashedPassword        = user.Password;
         bool    verificationSucceeded = (hashedPassword != null && CodeFirstCrypto.VerifyHashedPassword(hashedPassword, password));
         if (verificationSucceeded)
         {
             user.PasswordFailuresSinceLastSuccess = 0;
         }
         else
         {
             int failures = user.PasswordFailuresSinceLastSuccess;
             if (failures != -1)
             {
                 user.PasswordFailuresSinceLastSuccess += 1;
                 user.LastPasswordFailureDate           = DateTime.UtcNow;
             }
         }
         context.SaveChanges();
         //if (verificationSucceeded)
         //{
         //    return user.Username;
         //}
         //else
         //{
         //    return string.Empty;
         //}
         return(verificationSucceeded);
     }
 }
示例#9
0
 public override bool DeleteAccount(string userName)
 {
     if (string.IsNullOrEmpty(userName))
     {
         throw CreateArgumentNullOrEmptyException("userName");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
         if (user == null)
         {
             return(false);
         }
         context.User.Remove(user);
         context.SaveChanges();
         return(true);
     }
 }
示例#10
0
 public override bool ConfirmAccount(string accountConfirmationToken)
 {
     if (string.IsNullOrEmpty(accountConfirmationToken))
     {
         throw CreateArgumentNullOrEmptyException("accountConfirmationToken");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic row = context.User.FirstOrDefault(Usr => Usr.ConfirmationToken == accountConfirmationToken);
         if (row != null)
         {
             row.IsConfirmed = true;
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         var users = context.User.Where(usr => usernames.Contains(usr.Username)).ToList();
         var roles = context.Roles.Where(rl => roleNames.Contains(rl.RoleName)).ToList();
         foreach (User user_loopVariable in users)
         {
             var user = user_loopVariable;
             foreach (Role role_loopVariable in roles)
             {
                 var role = role_loopVariable;
                 if (!user.Roles.Contains(role))
                 {
                     user.Roles.Add(role);
                 }
             }
         }
         context.SaveChanges();
     }
 }
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 var users = context.User.Where(usr => usernames.Contains(usr.Username)).ToList();
                 var roles = context.Roles.Where(rl => roleNames.Contains(rl.RoleName)).ToList();
                 foreach (User user_loopVariable in users)
                 {
                    var user = user_loopVariable;
                     foreach (Role role_loopVariable in roles)
                     {
                       var  role = role_loopVariable;
                         if (!user.Roles.Contains(role))
                         {
                             user.Roles.Add(role);
                         }
                     }
                 }
                 context.SaveChanges();
             }
 }
 public override void CreateRole(string roleName)
 {
     if (string.IsNullOrEmpty(roleName))
     {
         throw CreateArgumentNullOrEmptyException("roleName");
     }
     using (BusinessFlowContext context = new BusinessFlowContext())
     {
         dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
         if (role != null)
         {
             throw new InvalidOperationException(string.Format("Role exists: {0}", roleName));
         }
         Role NewRole = new Role
         {
             RoleId   = Guid.NewGuid(),
             RoleName = roleName
         };
         context.Roles.Add(NewRole);
         context.SaveChanges();
     }
 }
 public override void CreateRole(string roleName)
 {
     if (string.IsNullOrEmpty(roleName))
             {
                 throw CreateArgumentNullOrEmptyException("roleName");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
                 if (role != null)
                 {
                     throw new InvalidOperationException(string.Format("Role exists: {0}", roleName));
                 }
                 Role NewRole = new Role
                 {
                     RoleId = Guid.NewGuid(),
                     RoleName = roleName
                 };
                 context.Roles.Add(NewRole);
                 context.SaveChanges();
             }
 }
 public override bool ExtendedValidateUser(string userNameOrEmail, string password)
 {
     if (string.IsNullOrEmpty(userNameOrEmail))
             {
                 throw CreateArgumentNullOrEmptyException("userNameOrEmail");
             }
             if (string.IsNullOrEmpty(password))
             {
                 throw CreateArgumentNullOrEmptyException("password");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 User user = null;
                 user = context.User.FirstOrDefault(Usr => Usr.Username == userNameOrEmail);
                 if (user == null)
                 {
                     user = context.User.FirstOrDefault(Usr => Usr.Email == userNameOrEmail);
                 }
                 if (user == null)
                 {
                     return false;
                 }
                 if (!user.IsConfirmed)
                 {
                     return false;
                 }
                 dynamic hashedPassword = user.Password;
                 bool verificationSucceeded = (hashedPassword != null && CodeFirstCrypto.VerifyHashedPassword(hashedPassword, password));
                 if (verificationSucceeded)
                 {
                     user.PasswordFailuresSinceLastSuccess = 0;
                 }
                 else
                 {
                     int failures = user.PasswordFailuresSinceLastSuccess;
                     if (failures != -1)
                     {
                         user.PasswordFailuresSinceLastSuccess += 1;
                         user.LastPasswordFailureDate = DateTime.UtcNow;
                     }
                 }
                 context.SaveChanges();
                 //if (verificationSucceeded)
                 //{
                 //    return user.Username;
                 //}
                 //else
                 //{
                 //    return string.Empty;
                 //}
                 return verificationSucceeded;
             }
 }
示例#16
0
        public override string CreateAccount(string userName, string password, string email, out MembershipCreateStatus status, bool requireConfirmationToken)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
            }
            string hashedPassword = CodeFirstCrypto.HashPassword(password);

            if (hashedPassword.Length > 128)
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
            }
            if (string.IsNullOrEmpty(userName))
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName);
            }
            if (string.IsNullOrEmpty(email))
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.InvalidEmail);
            }
            using (BusinessFlowContext context = new BusinessFlowContext())
            {
                dynamic user      = context.User.FirstOrDefault(Usr => Usr.Username == userName);
                dynamic emailuser = context.User.FirstOrDefault(Usr => Usr.Email == email);
                if (user != null)
                {
                    throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
                }
                if (emailuser != null)
                {
                    throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail);
                }
                string token = null;
                if (requireConfirmationToken)
                {
                    token = CodeFirstCrypto.GenerateToken();
                }
                int  defaultNumPasswordFailures = 0;
                User NewUser = new User
                {
                    UserId              = Guid.NewGuid(),
                    Username            = userName,
                    Password            = hashedPassword,
                    IsConfirmed         = !requireConfirmationToken,
                    Email               = email,
                    ConfirmationToken   = token,
                    CreateDate          = DateTime.UtcNow,
                    PasswordChangedDate = DateTime.UtcNow,
                    PasswordFailuresSinceLastSuccess = defaultNumPasswordFailures,
                    LastPasswordFailureDate          = DateTime.UtcNow
                };

                context.User.Add(NewUser);
                try
                {
                    context.SaveChanges();
                }

                catch (Exception e)
                {
                }
                status = MembershipCreateStatus.Success;
                return(token);
            }
        }
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     if (string.IsNullOrEmpty(roleName))
             {
                 throw CreateArgumentNullOrEmptyException("roleName");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
                 if (role == null)
                 {
                     throw new InvalidOperationException("Role not found");
                 }
                 if (throwOnPopulatedRole)
                 {
                     dynamic usersInRole = role.Users.Any;
                     if (usersInRole)
                     {
                         throw new InvalidOperationException(string.Format("Role populated: {0}", roleName));
                     }
                 }
                 else
                 {
                     foreach (User usr_loopVariable in role.Users)
                     {
                        var usr = usr_loopVariable;
                         context.User.Remove(usr);
                     }
                 }
                 context.Roles.Remove(role);
                 context.SaveChanges();
                 return true;
             }
 }
 public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
 {
     using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 foreach (string username_loopVariable in usernames)
                 {
                    var username = username_loopVariable;
                     string us = username;
                     User user = context.User.FirstOrDefault(u => u.Username == us);
                     if (user != null)
                     {
                         foreach (string rolename_loopVariable in roleNames)
                         {
                            var rolename = rolename_loopVariable;
                             var rl = rolename;
                             Role role = user.Roles.FirstOrDefault(r => r.RoleName == rl);
                             if (role != null)
                             {
                                 user.Roles.Remove(role);
                             }
                         }
                     }
                 }
                 context.SaveChanges();
             }
 }
 public override bool ConfirmAccount(string accountConfirmationToken)
 {
     if (string.IsNullOrEmpty(accountConfirmationToken))
             {
                 throw CreateArgumentNullOrEmptyException("accountConfirmationToken");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic row = context.User.FirstOrDefault(Usr => Usr.ConfirmationToken == accountConfirmationToken);
                 if (row != null)
                 {
                     row.IsConfirmed = true;
                     context.SaveChanges();
                     return true;
                 }
                 return false;
             }
 }
 public override bool ChangePassword(string userName, string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(userName))
             {
                 throw CreateArgumentNullOrEmptyException("userName");
             }
             if (string.IsNullOrEmpty(oldPassword))
             {
                 throw CreateArgumentNullOrEmptyException("oldPassword");
             }
             if (string.IsNullOrEmpty(newPassword))
             {
                 throw CreateArgumentNullOrEmptyException("newPassword");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
                 if (user == null)
                 {
                     return false;
                 }
                 dynamic hashedPassword = user.Password;
                 bool verificationSucceeded = (hashedPassword != null && CodeFirstCrypto.VerifyHashedPassword(hashedPassword, oldPassword));
                 if (verificationSucceeded)
                 {
                     user.PasswordFailuresSinceLastSuccess = 0;
                 }
                 else
                 {
                     int failures = user.PasswordFailuresSinceLastSuccess;
                     if (failures != -1)
                     {
                         user.PasswordFailuresSinceLastSuccess += 1;
                         user.LastPasswordFailureDate = DateTime.UtcNow;
                     }
                     context.SaveChanges();
                     return false;
                 }
                 dynamic newhashedPassword = CodeFirstCrypto.HashPassword(newPassword);
                 if (newhashedPassword.Length > 128)
                 {
                     throw new ArgumentException("Password too long");
                 }
                 user.Password = newhashedPassword;
                 user.PasswordChangedDate = DateTime.UtcNow;
                 context.SaveChanges();
                 return true;
             }
 }
 public override bool ResetPasswordWithToken(string token, string newPassword)
 {
     if (string.IsNullOrEmpty(newPassword))
             {
                 throw CreateArgumentNullOrEmptyException("newPassword");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic user = context.User.FirstOrDefault(Usr => Usr.PasswordVerificationToken == token && Usr.PasswordVerificationTokenExpirationDate > DateTime.UtcNow);
                 if (user != null)
                 {
                     dynamic newhashedPassword = CodeFirstCrypto.HashPassword(newPassword);
                     if (newhashedPassword.Length > 128)
                     {
                         throw new ArgumentException("Password too long");
                     }
                     user.Password = newhashedPassword;
                     user.PasswordChangedDate = DateTime.UtcNow;
                     user.PasswordVerificationToken = null;
                     user.PasswordVerificationTokenExpirationDate = null;
                     context.SaveChanges();
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
 }
        public override string CreateAccount(string userName, string password, string email,out MembershipCreateStatus status, bool requireConfirmationToken)
        {
            if (string.IsNullOrEmpty(password))
                    {
                        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
                    }
                    string hashedPassword = CodeFirstCrypto.HashPassword(password);
                    if (hashedPassword.Length > 128)
                    {
                        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
                    }
                    if (string.IsNullOrEmpty(userName))
                    {
                        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName);
                    }
                    if (string.IsNullOrEmpty(email))
                    {
                        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidEmail);
                    }
                    using (BusinessFlowContext context = new BusinessFlowContext())
                    {
                        dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
                        dynamic emailuser = context.User.FirstOrDefault(Usr => Usr.Email == email);
                        if (user != null)
                        {
                            throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
                        }
                        if (emailuser != null)
                        {
                            throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail);
                        }
                        string token = null;
                        if (requireConfirmationToken)
                        {
                            token = CodeFirstCrypto.GenerateToken();
                        }
                        int defaultNumPasswordFailures = 0;
                        User NewUser = new User
                        {
                            UserId = Guid.NewGuid(),
                            Username = userName,
                            Password = hashedPassword,
                            IsConfirmed = !requireConfirmationToken,
                            Email = email,
                            ConfirmationToken = token,
                            CreateDate = DateTime.UtcNow,
                            PasswordChangedDate = DateTime.UtcNow,
                            PasswordFailuresSinceLastSuccess = defaultNumPasswordFailures,
                            LastPasswordFailureDate = DateTime.UtcNow
                        };

                        context.User.Add(NewUser);
                        try
                        {
                            context.SaveChanges();
                        }

                        catch (Exception e)
                        {

                        }
                        status = MembershipCreateStatus.Success;
                        return token;
                    }
        }
 public override bool DeleteAccount(string userName)
 {
     if (string.IsNullOrEmpty(userName))
             {
                 throw CreateArgumentNullOrEmptyException("userName");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
                 if (user == null)
                 {
                     return false;
                 }
                 context.User.Remove(user);
                 context.SaveChanges();
                 return true;
             }
 }
 public void Save()
 {
     context.SaveChanges();
 }
 public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
 {
     if (string.IsNullOrEmpty(userName))
             {
                 throw CreateArgumentNullOrEmptyException("userName");
             }
             using (BusinessFlowContext context = new BusinessFlowContext())
             {
                 dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
                 if (user == null)
                 {
                     throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                 }
                 if (!user.IsConfirmed)
                 {
                     throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                 }
                 string token = null;
                 if (user.PasswordVerificationTokenExpirationDate > DateTime.UtcNow)
                 {
                     token = user.PasswordVerificationToken;
                 }
                 else
                 {
                     token = CodeFirstCrypto.GenerateToken();
                 }
                 user.PasswordVerificationToken = token;
                 user.PasswordVerificationTokenExpirationDate = DateTime.UtcNow.AddMinutes(tokenExpirationInMinutesFromNow);
                 context.SaveChanges();
                 return token;
             }
 }