Esempio n. 1
0
        private Access( User.User _user, AccessLevel _level, Object _object )
        {
            if ( _user == null || _object == null )
                throw new AccessException(
                    Global.StaticResourceManager.GetStringResource("ACCESS_INVALID_USER_PARAMS"));

            User = _user;
            Level = _level;
            AccessObject = _object;
        }
Esempio n. 2
0
 /// <summary>
 /// Gets user from a 'users' list
 /// </summary>
 /// <param name="login"></param>
 /// <returns></returns>
 public static User Get( string login )
 {
     var strg = FindLogin( login );
     if ( strg != null ) {
         var tmp = strg.Item1.Split(':');
         var user = new User();
         user.Credentials.Login = login;
         user.Credentials.hashed_pwd = tmp[1];
         return user;
     }
     return null;
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a new user
 /// </summary>
 /// <param name="login"></param>
 /// <param name="passwd"></param>
 /// <returns></returns>
 public static User New( string login, string passwd )
 {
     if ( FindLogin( login ) != null ) {
         Errors.Messages.DisplayError(
             Global.StaticResourceManager.GetStringResource( "USER_ALREADY_EXISTS" ),
             "Adding a new user",
             "",
             DateTime.Now);
         return Get( login );
     }
     var user = new User();
     user.Credentials = new UserCredentials();
     user.Credentials.Login = login;
     user.Credentials.Password = passwd;
     SaveToUsersList( user );
     return user;
 }
Esempio n. 4
0
 /// <summary>
 /// Adds a new user to a userlist file
 /// </summary>
 /// <param name="_user"></param>
 private static void SaveToUsersList( User _user )
 {
     CreateUsersList();
     CreateBackup();
     var fl = FindLogin(_user.Credentials.Login);
     var usr_strg = _user.Credentials.Login + ":" + _user.Credentials.hashed_pwd;
     if ( fl == null ) {
         using ( var fs = new FileStream( users_file_path, FileMode.Append, FileAccess.Write ) ) {
             var sw = new StreamWriter( fs );
             sw.WriteLine(usr_strg);
             sw.Close();
         }
     } else {
         using ( var fs = new FileStream( users_file_path, FileMode.Append, FileAccess.Write ) ) {
             var sw = new StreamWriter( fs );
             sw.BaseStream.Position = fl.Item2;
             sw.WriteLine(usr_strg);
             sw.Close();
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Removes user from a userlist file
 /// </summary>
 /// <param name="_user"></param>
 private static void RemoveFromUsersList( User _user )
 {
     throw new NotImplementedException("Method isn't implemented");
 }
Esempio n. 6
0
 /// <summary>
 /// Adds a new user to a userlist file
 /// </summary>
 /// <param name="_user"></param>
 /// <param name="new_password"></param>
 private static void ChangePassword( User _user, string new_password )
 {
     _user.Credentials.Password = new_password;
 }
Esempio n. 7
0
        /// <summary>
        /// Getting an instance for given user, level and object
        /// </summary>
        /// <param name="_user"></param>
        /// <param name="_level"></param>
        /// <param name="_object"></param>
        /// <returns></returns>
        public static Access Instance( User.User _user, AccessLevel _level, Object _object )
        {
            // Let's look in our array. Do we already have a such object?
            foreach ( var al in instances ) {
                if ( al.User.Credentials.Login == _user.Credentials.Login &&
                    al.Level == _level &&
                    al.AccessObject == _object ) {
                    return al;
                }
            }

            // If we don't have => let's create a new Access instance and add it to our array
            var new_acc = new Access( _user, _level, _object );
            instances.Add( new_acc );
            new_acc.Save();
            return new_acc;
        }