private void buttonLoginCreate_Click(object sender, RoutedEventArgs e) { LoginWindow loginWin = new LoginWindow(this); loginWin.Owner = this; if (loginWin.ShowDialog() == true) { if (this.credentials == null) { return; } try { this.user = new UserContents(credentials, true); LoggedIn = true; if (this.machine == null) { buttonCreateSelectMachine_Click(sender, e); } else { RefreshDisplayedMachineInfo(); } } catch (ActionException ex) { new SystemMessage(ex).ShowDialog(); //MessageBox.Show(ex.Message, ex.Title); } } }
public UserContents GetUserWithMachines(Credentials c) { UserContents u = (UserContents)GetUser(c); List <Machine> ml; List <MachineContents> machinelist; using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (!Authenticate(context, c)) { return(null); } //throw new Exception("unauthorized access detected"); machinelist = new List <MachineContents>(); u.Id = LoginToId(context, u.Login); ml = (from o in context.Machines where o.user_id == u.Id select o).ToList(); } foreach (Machine m in ml) { MachineContents m1 = new MachineContents(m.machine_name, m.machine_description); m1.Id = m.machine_id; m1.User = m.user_id; machinelist.Add(m1); } u.Machines = machinelist; return(u); }
public UserIdentity GetUser(Credentials c) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (LoginExists(context, c.Login)) { if (Authenticate(context, c)) { int id = LoginToId(context, c.Login); User u1 = (from o in context.Users where o.user_id == id select o).SingleOrDefault(); UserIdentity u = new UserContents(u1.user_login, u1.user_pass, u1.user_fullname, u1.user_email); u.LastLogin = (DateTime)u1.user_lastlogin; u.Id = u1.user_id; return(u); } else { //throw new Exception("wrong password"); return(null); } } else { //throw new Exception("no such user"); return(null); } } }
private void buttonLogout_Click(object sender, RoutedEventArgs e) { LoggedIn = false; credentials = null; user = null; machine = null; }
private UserContents getUser() { UserContents u = new UserContents(this.getLogin(), Security.ComputeHash(this.UserPassword.Password), this.UserFullName.Text, this.UserEmail.Text); return(u); }
public void CreateAccountTest() { Credentials c = new Credentials("testUserLogin", Security.ComputeHash("testUserPass")); UserContents uc = new UserContents(c, "Test User", "*****@*****.**"); guiConn.AddUser(uc); Assert.AreEqual(guiConn.GetUser(c), uc); }
private UserContents getUser() { UserContents u = new UserContents(); u.Login = this.getLogin(); u.Password = Security.ComputeHash(this.UserPassword.Password); u.Name = this.UserFullName.Text; u.Email = this.UserEmail.Text; return(u); }
public void AddUser(Credentials c, UserContents u) { try { using (FileSyncModelClient cl = new FileSyncModelClient()) { cl.AddUser(c, u); } } catch (Exception ex) { throw new ActionException("Unable to create new user account.", ActionType.User, MemeType.Fuuuuu, ex); } }
public bool AddUser(UserContents u) { var cl = new Ref.FileSyncModelClient(); try { bool result = false; result = cl.AddUser(u); cl.Close(); return(result); } catch (Exception ex) { cl.Abort(); throw new ActionException("Unable to create new user account.", ActionType.User, ex); } }
private void buttonCreateSelectMachine_Click(object sender, RoutedEventArgs e) { if (!LoggedIn) { return; } //temporary UserContents user = connection.GetUserWithMachines(credentials); //new UserContents(credentials, true).Machines; // UserActions.GetContents(this.credentials).Machines; this.machine = connection.GetMachineWithDirs(credentials, user.Machines[0]); //this.machine = user.Machines[0]; //new MachineContents(credentials, machines[0], true, false, true); //MachineActions.GetContets(credentials, machines[0]); RefreshDisplayedMachineInfo(); if (machine != null) { return; } //end of temporary if (new MachineWindow(this).ShowDialog() == false) { return; } if (this.machine == null) { LoggedInAndChosenMachine = false; return; } RefreshDisplayedMachineInfo(); try { //foreach (DirContents dc in MachineActions.GetDirsContents(credentials, machine)) // directories.Add(dc); //if (PropertyChanged != null) // PropertyChanged(this, new PropertyChangedEventArgs("Directories")); } catch (ActionException ex) { MessageBox.Show(ex.Message, ex.Title); } RefreshDisplayedDirectories(); }
public void DelUser(Credentials c) { UserContents u = GetUser(c); using (filesyncEntities context = new filesyncEntities()) { try { int id = LoginToId(u.Login); var u1 = (from o in context.Users where o.user_id == id select o).Single(); context.Users.DeleteObject(u1); context.SaveChanges(); } catch { throw new Exception("no such user"); } } }
public UserContents GetUserWithMachines(Credentials c) { var cl = new Ref.FileSyncModelClient(); try { UserContents u = null; u = cl.GetUserWithMachines(c); cl.Close(); if (u == null) { throw new ActionException("Received a null object.", ActionType.User); } return(u); } catch (Exception ex) { cl.Abort(); throw new ActionException("Unable to get machines for a given user.", ActionType.User, ex); } }
public void AddUser(Credentials c, UserContents u) { if (LoginExists(u.Login)) { throw new Exception("user already exists"); } else { //TODO: don't use password directly User u1 = User.CreateUser(1, u.Login, u.Password); u1.user_email = u.Email; u1.user_fullname = u.Name; u1.user_lastlogin = DateTime.Now; using (filesyncEntities context = new filesyncEntities()) { context.Users.AddObject(u1); context.SaveChanges(); } } }
public void GetMachineList(Credentials c, UserContents u) { List <MachineContents> machinelist = new List <MachineContents>(); u.Id = LoginToId(u.Login); using (filesyncEntities context = new filesyncEntities()) { List <Machine> ml = (from o in context.Machines where o.user_id == u.Id select o).ToList(); foreach (Machine m in ml) { MachineContents m1 = new MachineContents(m.machine_name, m.machine_description); m1.Id = m.machine_id; m1.User = m.user_id; machinelist.Add(m1); } u.Machines = machinelist; } }
public bool AddUser(UserContents u) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (LoginExists(context, u.Login)) { //throw new Exception("user already exists"); return(false); } else { //TODO: don't use password directly User u1 = User.CreateUser(1, u.Login, u.Password); u1.user_email = u.Email; u1.user_fullname = u.Name; u1.user_lastlogin = DateTime.Now; context.Users.AddObject(u1); context.SaveChanges(); } } return(true); }
public bool DelUser(Credentials c) { UserContents u = (UserContents)GetUser(c); bool result = false; using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (!Authenticate(context, c)) { return(result); } int id = LoginToId(context, u.Login); var u1 = (from o in context.Users where o.user_id == id select o).SingleOrDefault(); if (u1 != null) { context.Users.DeleteObject(u1); context.SaveChanges(); result = true; } } return(result); }
public void GetMachineList(Credentials c, UserContents u) { throw new Exception("not implemented"); }