//JDR: OVERLOAD 3: Private method to set static user if ID found private static bool SetActiveUser(int UserID) //JDR: Use UserID for populating ActiveUser { using (BankDB db = new BankDB()) { var activeUser = db.User.Find(UserID); if (activeUser == null) { return(false); } UserAccount.SetActiveUser(activeUser); return(true); } }
//JDR: Overload 1: Verify if active user in seccion public static bool IsLoggedIn() { var UserID = HttpContext.Current.Session["UserID"] ?? null; if (UserID != null) { var result = UserAccount.SetActiveUser(UserID.ToString()); if (result == false) { return(false); } } return(UserID != null ? true : false); }
public static bool Login(ref User user) { using (BankDB db = new BankDB()) { string Email = user.Email; string HashPassword = GLOBAL.Hash(user.Password, UserAccount.PasswordSalt); var activeUser = db.User.Where(userRow => userRow.Email == Email && userRow.Password == HashPassword).FirstOrDefault(); if (activeUser == null) { return(false); } user = activeUser; UserAccount.SetSession(activeUser); //JDR: Store user login credentials in global Session UserAccount.SetActiveUser(activeUser); //JDR: Set static variable for active user for all to call return(true); } }
//JDR: OVERLOAD 4: Private method to set static user if ID found private static bool SetActiveUser(string UserID) //JDR: Use UserID for populating ActiveUser, convert str to int { return(UserAccount.SetActiveUser(Int32.Parse(UserID))); }