public User(User u) { _username = u.UserName; _state = u.State; _nickname = u.NickName; _authLevel = u.AuthLevel; }
/// <summary> /// returns the internal User object corresponding to a user /// </summary> /// <param name="username">the email id of the user in question</param> /// <returns>the internal user object used to manage the user</returns> public User GetUser(string username) { foreach (User user in UserList) { if (username == user.UserName) { //found a user that is allowed. return user; } } User newUser = new User(username, "UnAuth", UserState.Invalid, UserAuthLevel.Unauthorized); return newUser; }
//add user function to add to users.ini public bool AddUser(string username, string nickname, UserAuthLevel auth) { bool result = false; Logger.LogInformation("runtime add user request for " + username + "(" + nickname + ") " + auth.ToString()); UserState state = UserState.Allowed; User newUser = new User(username, nickname, state, auth); //remotely added try { //todo(0) fix the obvious bug here (append and dont introdude a new line) StreamWriter writer = File.AppendText(SessionSettings.usersfile); writer.WriteLine(); //extra! writer.WriteLine(username + "|" + nickname + "|" + auth.ToString()); writer.Flush(); writer.Close(); result = true; } catch (Exception ex) { Logger.LogInformation("error adding user to usersfile"); Logger.LogException(ex); result = false; } return result; }