public AddEditUser(TabletUser user) { InitializeComponent(); action = SaveMode.Edit; currentUser = user; DisplayData(); }
public AddEditUser() { InitializeComponent(); action = SaveMode.Add; currentUser = new TabletUser(); DisplayData(); }
async void Login_Clicked(System.Object sender, System.EventArgs e) { var user = TabletUser.AuthenticateUser(Username.Text, Password.Text); if (user != null && user.Enabled) { App.IsLoggedIn = true; App.LoggedInUser = user.Username; if (!user.AccountActivated) { user.ToggleAccountActivation(); } await Navigation.PopModalAsync(); } else { App.IsLoggedIn = false; Password.Text = string.Empty; Password.Focus(); LoggedInStatus.Text = "Invalid username and/or password."; } }
protected void SetupDatabase() { int numberOfRoles = 0; TabletUser defaultUser; try { using (SQLiteConnection conn = new SQLiteConnection(DatabaseLocation)) { conn.CreateTable <TabletUser>(); defaultUser = conn.Get <TabletUser>("admin"); } } catch { using (SQLiteConnection conn = new SQLiteConnection(DatabaseLocation)) { conn.CreateTable <TabletRole>(); numberOfRoles = conn.Table <TabletRole>().Count(); } defaultUser = new TabletUser() { Username = "******", Password = "******", Firstname = "System", Lastname = "Administrator", AccountActivated = true, Enabled = true }; defaultUser.CreateUser(); TabletRole existingRole; List <TabletRole> roles = new List <TabletRole>(); roles.Add(new TabletRole() { Role = "admin", RoleDescription = "System administrator" }); roles.Add(new TabletRole() { Role = "coordinator", RoleDescription = "Study coordinator" }); roles.Add(new TabletRole() { Role = "supervisor", RoleDescription = "District supervisor" }); roles.Add(new TabletRole() { Role = "user", RoleDescription = "General user (lowest level permissions)" }); foreach (var role in roles) { try { using (SQLiteConnection conn = new SQLiteConnection(DatabaseLocation)) { conn.CreateTable <TabletRole>(); existingRole = conn.Get <TabletRole>(role.Role); } } catch { role.CreateRole(); } } defaultUser.Roles = roles; using (SQLiteConnection conn = new SQLiteConnection(DatabaseLocation)) { conn.CreateTable <TabletUserRole>(); conn.UpdateWithChildren(defaultUser); } // Test roles have saved using (SQLiteConnection conn = new SQLiteConnection(DatabaseLocation)) { var kw = conn.GetWithChildren <TabletUser>("admin"); } } }