コード例 #1
0
        //Called on every Admin login
        public bool RestoreAdmin()
        {
            OperationsManager  manager = new OperationsManager();
            List <OperationVO> all     = manager.GetAll();
            UserVO             admin   = GetUserByName(ADMIN_USER_NAME);

            if (admin == null)
            {
                UserVO user = new UserVO();
                user.Username = ADMIN_USER_NAME;
                user.Password = GenerateHash(ADMIN_PASSWORD);
                user.IsActive = true;

                if (Insert(user) < 0)
                {
                    return(false);
                }

                admin = user;
            }

            if (all != null)
            {
                return(manager.AssignPermissionsToUser(admin, all));
            }

            return(false);
        }
コード例 #2
0
        public AuthenticationResult Authenticate(UserVO user)
        {
            try
            {
                if (user.Username == ADMIN_USER_NAME)
                {
                    RestoreAdmin();
                }

                List <UserVO> all = GetAll();

                if (all.Count == 0)
                {
                    return(AuthenticationResult.NO_USERS_IN_DB);
                }

                foreach (UserVO curUser in all)
                {
                    if (curUser.Username == user.Username)
                    {
                        user.IsActive = curUser.IsActive;

                        if (ValidateHash(user.Password, curUser.Password))
                        {
                            if (curUser.IsActive)
                            {
                                OperationsManager manager = new OperationsManager();
                                user.Id = curUser.Id;

                                if (manager.HasPermission(OperationsManager.LOGIN_LOGOUT, user))
                                {
                                    user.Permissions = manager.GetOperationsOfUser(user);

                                    return(AuthenticationResult.SUCCESSFUL);
                                }
                                else
                                {
                                    return(AuthenticationResult.NO_PERMISSION);
                                }
                            }
                            else
                            {
                                return(AuthenticationResult.NOT_ACTIVE);
                            }
                        }
                        else
                        {
                            return(AuthenticationResult.WRONG_PASSWORD);
                        }
                    }
                }

                return(AuthenticationResult.WRONG_USER_NAME);
            }
            catch
            {
                return(AuthenticationResult.CONNECTION_ERROR);
            }
        }