public static bool InsertUser(RegisterVModel userRegister) { using (var model = new fmDbDataModel()) { try { string hashedPassword = SecurityManager.CalculateHash(userRegister.Password); fm_Users newUser = new fm_Users() { Name = userRegister.Name, Email = userRegister.Email, Password = hashedPassword, Salt = SecurityManager.GetSalt(), // later will be taken from database and fetched with new password to compare with the old one InsertTime = DateTime.Now, AccountStatus = (int)AccountStatus.Active }; // Adding the user to the currently connected database and now performing the same operation on the mirror ones. model.fm_Users.Add(newUser); model.SaveChanges(); DataOperationManager.Synch(new Func <RegisterVModel, bool>(InsertUser), new object[] { userRegister }); return(true); } catch (Exception e) { DataOperationManager.VerifyResult(new Func <RegisterVModel, bool>(InsertUser), new object[] { userRegister }, MethodReturnStatus.Error); _log.ErrorFormat("There was an error with inserting user to db. Message: {0}, Stacktrace: {1}", e.Message, e.StackTrace); return(false); } } }
public static bool InitializeUserLogin(fm_Users User) { try { using (var model = new fmDbDataModel()) { UserSingleton.CreateUserSingleton(User); HttpContext.Current.Session["USER_ID"] = User.Id; HttpContext.Current.Session["USER_EMAIL"] = UserSingleton.Instance.Email; User.LastSuccessfullLogin = DateTime.Now; User.IsOnline = (int)UserCurrentStatus.Online; model.Entry <fm_Users>(User).State = System.Data.Entity.EntityState.Modified; model.SaveChanges(); } return(true); } catch (Exception e) { _log.ErrorFormat("There was an error with initializing user login. Message: {0}, Stacktrace: {1}", e.Message, e.StackTrace); return(false); } }
public static void CreateUserSingleton(fm_Users fetched) { if (_instance == null) { _instance = new Lazy <UserSingleton>(() => new UserSingleton(fetched)); } }
private UserSingleton(fm_Users fetched) { Id = fetched.Id; Name = fetched.Name; Email = fetched.Email; DefaultCurrency = fetched.DefaultCurrency ?? (int)CurrencyType.PLN; }
public static LoginVModel UserSignIn(LoginVModel UserLogin) { fm_Users userExists = null; try { using (var model = new fmDbDataModel()) { userExists = model.fm_Users.FirstOrDefault(user => user.Email.Equals(UserLogin.Email)); if (userExists == null) { return((LoginVModel)DataOperationManager.VerifyResult(new Func <LoginVModel, LoginVModel>(UserSignIn), new object[] { UserLogin }, HostCommunication.HostModels.MethodReturnStatus.Null)); } string hashedPassword = SecurityManager.CalculateHash(UserLogin.Password, userExists.Salt); if (SecurityManager.ComparePasswords(userExists.Password, hashedPassword)) { bool isInitialized = UserManager.InitializeUserLogin(userExists); if (isInitialized) { return(new LoginVModel() { Email = UserLogin.Email, Password = hashedPassword }); } } _log.InfoFormat("User with {0} email could not login.", UserLogin.Email); return(null); } } catch (Exception e) { return((LoginVModel)DataOperationManager.VerifyResult(new Func <LoginVModel, LoginVModel>(UserSignIn), new object[] { UserLogin }, HostCommunication.HostModels.MethodReturnStatus.Error)); } }