public static UserInfo GetUserByName(string userName, bool isTest = false) { ISprocCalls sprocCalls = AppTools.InitSprocCalls(isTest); UserInfo user = sprocCalls.UserInfoGetByUser(userName); if (user != null) { user.GroupUsers = GetGroupsByUserName(userName, sprocCalls); } return(user); }
public static bool DeleteUser(string userName, bool isTest = false) { try { IMembershipTools membershipTools = AppTools.InitMembershipTools(isTest); return(membershipTools.DeleteUser(userName)); } catch (Exception ex) { DBCommands.RecordError(ex); return(false); } }
public static UserInfo GetUserByCode(CompleteRec model, string code, bool isTest = false) { UserInfo user = null; try { ISprocCalls sprocCalls = AppTools.InitSprocCalls(isTest); IMembershipTools membershipTools = AppTools.InitMembershipTools(isTest); user = sprocCalls.UserInfoGetByCode(code); if (user.Email == model.Email) { if (membershipTools.UpdatePassword(model.UserName, model.Password)) { string errorMessage = string.Empty; user.GroupUsers = GetGroupsByUserName(user.UserName, sprocCalls); user.RecoverCode = null; UpdateUser(user, out errorMessage, isTest); if (string.IsNullOrEmpty(errorMessage) == false) { throw new Exception(errorMessage); } } } else { throw new Exception("User recovered email does not match."); } return(user); } catch (Exception ex) { DBCommands.RecordError(ex); } return(user); }
public static void RecoverPassword(RecoverModel model, string location, out string errorMessage, bool isTest = false) { try { ISprocCalls sprocCalls = AppTools.InitSprocCalls(isTest); errorMessage = string.Empty; UserInfo user = sprocCalls.UserInfoGetByUser(model.UserName); if (model.Email == user.Email) { string code = RandomCode(7); while (sprocCalls.UserInfoGetByCode(code) != null) { code = RandomCode(7); } user.GroupUsers = GetGroupsByUserName(model.UserName, sprocCalls); user.RecoverCode = RandomCode(7); if (sprocCalls.UserInfoUpdate(user) == false) { errorMessage = "Error recovering password."; } else if (SendRecoverEmail(user, location, isTest) == false) { errorMessage = "Error sending email."; } } else { errorMessage = (user != null) ? "Email and username is not valid." : "Error loading user"; } } catch (Exception ex) { DBCommands.RecordError(ex); errorMessage = ex.Message; } }
private static bool SendRecoverEmail(UserInfo user, string location, bool isTest) { try { StringBuilder builder = new StringBuilder(); builder.Append("Hello, we have received your message that your password has been forgotten. To reset your password please click the link below.<br />"); builder.Append(@"http://localhost:61860/" + location + "/CompeRec/" + user.RecoverCode); IEmailTools emailTools = AppTools.InitEmailTools(isTest); if (emailTools.SendEmail(user.Email, builder.ToString()) == false) { throw new Exception("Error sending email."); } return(true); } catch (Exception ex) { DBCommands.RecordError(ex); return(false); } }
public static void InsertUser(UserInfo user, out string errorMessage, bool isTest = false) { try { errorMessage = ValidateUser(user); if (string.IsNullOrEmpty(errorMessage)) { IMembershipTools membershipTools = AppTools.InitMembershipTools(isTest); ISprocCalls sprocCalls = AppTools.InitSprocCalls(isTest); if (membershipTools.CreateUser(user.UserName, user.Email) == false || sprocCalls.UserInfoUpdate(user) == false) { errorMessage = "Error saving user information."; } } } catch (Exception ex) { DBCommands.RecordError(ex); errorMessage = ex.Message; } }