public RegisterOneViewModel() { RegisterStepOne = new Command <UserAuthModel>(async(auth) => { IsBusy = true; var resp = await HttpService.PostRequest <ResponseModel <UserModel>, UserAuthModel>("user/register", auth); User = resp.Response; if (resp.Code != 200) { await Application.Current.MainPage.DisplayAlert($"{resp.Code}", $"{resp.Errors[0]}", "OK"); IsBusy = false; } else { FirstLogin.Execute(auth); } }); FirstLogin = new Command <UserAuthModel>(async(userauth) => { var resp = await HttpService.PostRequest <ResponseModel <string>, UserAuthModel>("user/login", userauth); HttpService.Token = resp.Response; if (!Application.Current.Properties.ContainsKey("Token")) { Application.Current.Properties.Add("Token", resp.Response); } else { Application.Current.Properties["Token"] = resp.Response; } await Application.Current.SavePropertiesAsync(); IsBusy = false; await Navigation.PushModalAsync(new CreateProfile(new CreateProfileViewModel(User))); }); }
public FirstLoginViewModel(FirstLogin firstLoginView, string username, string password) { view = firstLoginView; service = new PersonService(); User = new tblPerson(); User.Username = username; User.Password = password; }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { _migrationsHelper = new FirstLogin(model.UserName); Session["PersonProfileId"] = _migrationsHelper.PersonIdForSession(model.UserName, model.Password); return(RedirectToLocal(returnUrl)); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); _migrationsHelper = new FirstLogin(model.UserName); Session["PersonProfileId"] = _migrationsHelper.PersonIdForSession(model.UserName, model.Password); return(RedirectToAction("Index", "Social")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
/*-------------------------------------------------------------- SETTINGS --------------------------------------------------------------*/ private void GetCurrentUser() { try { Guid userUniqueIdentifier = Properties.Settings.Default.UniqueIdentifier; InTimeDbEntities intimeDb = new InTimeDbEntities(); DbSet <Person> personDbList = intimeDb.People; currentUser = (from Person in personDbList where Person.AccessCode == userUniqueIdentifier select Person).Single(); } catch (Exception e) { FirstLogin firstLogin = new FirstLogin(); firstLogin.ShowDialog(); firstLogin.Close(); GetCurrentUser(); } }
public void Load() { Logger.Log("Loading " + Username + " from the database", LogType.Debug); DataTable playerdb = Database.fillData("SELECT * FROM _players WHERE Name='" + Username.SqlEscape() + "'"); if (playerdb.Rows.Count == 0) { FirstLogin = DateTime.Now; LastLogin = DateTime.Now; Money = 0; Database.executeQuery("INSERT INTO _players (Name, IP, firstlogin, lastlogin, money, color) VALUES ('" + Username.SqlEscape() + "', '" + Ip.SqlEscape() + "', '" + FirstLogin.ToString("yyyy-MM-dd HH:mm:ss").SqlEscape() + "', '" + LastLogin.ToString("yyyy-MM-dd HH:mm:ss").SqlEscape() + "', 0, '" + Color.SqlEscape() + "')"); DataTable temp = Database.fillData("SELECT * FROM _players WHERE Name='" + Username.SqlEscape() + "'"); if (temp.Rows.Count != 0) { UID = int.Parse(temp.Rows[0]["UID"].ToString()); } temp.Dispose(); } else { UID = int.Parse(playerdb.Rows[0]["UID"].ToString()); FirstLogin = DateTime.Parse(playerdb.Rows[0]["firstlogin"].ToString()); LastLogin = DateTime.Now; Money = int.Parse(playerdb.Rows[0]["money"].ToString()); Color = playerdb.Rows[0]["color"].ToString(); //TODO Add total login and total Blocks } playerdb.Dispose(); LoadExtra(); //Because milk this.OnPlayerDisconnect.Important += delegate { Save(); }; }
public void Save() { Logger.Log("Saving " + Username + " to the database", LogType.Debug); List <string> commands = new List <string>(); commands.Add("UPDATE _players SET money=" + Money + ", lastlogin='******', firstlogin='******' WHERE UID=" + UID); commands.Add("UPDATE _players SET color='" + Color.SqlEscape() + "' WHERE UID=" + UID); DataSaved.Call(this, new DataSavedEventArgs(UID)); Database.executeQuery(commands.ToArray()); }
void Submit(object obj) { string encryptedString = (obj as PasswordBox).Password; if (encryptedString.Length < 5) { MessageBox.Show("Password has to be at least 5 characters long"); return; } string password = EncryptionHelper.Encrypt(encryptedString); if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(encryptedString)) { MessageBox.Show("Wrong user name or password"); return; } if (UserName.Equals("Admin") && !encryptedString.Equals("Admin123")) { MessageBox.Show("Wrong password for Admin"); return; } if (UserName.Equals("Admin") && encryptedString.Equals("Admin123")) { tblPerson adminInDb = personService.GetUserByUserNameAndPass(UserName, password); if (adminInDb == null) { tblPerson admin = new tblPerson(); admin.Username = UserName; admin.Password = password; adminInDb = personService.AddUser(admin); AdminMainView adminMain = new AdminMainView(adminInDb); adminMain.Show(); view.Close(); return; } else { AdminMainView adminMain = new AdminMainView(adminInDb); adminMain.Show(); view.Close(); return; } } tblPerson userInDb = personService.GetUserByUserName(UserName); if (userInDb == null) { FirstLogin firstLogin = new FirstLogin(UserName, password); firstLogin.Show(); view.Close(); return; } else { if (!userInDb.Password.Equals(password)) { MessageBox.Show("Wrong password for this user"); return; } tblPerson p; using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { p = (from x in context.tblPersons where x.Username == UserName select x).First(); } UserMain main = new UserMain(p); main.Show(); view.Close(); return; } }