/** * Gets the first session id related to that user * * @param $userid * * @return null */ public function GetFirstSessionID($userid) { $result = Result::GetFirst($this->GetAllUserSessions($userid)); if ($result != null) { return $result['session_id']; } return null; }
/** * Gets a computer * * @param $computer_id * * @return bool|mixed|null */ public function GetComputer($computer_id) { $result = Capsule::table('syscrack_game_computers')->where('computer_id', $computer_id)->get(); return !empty($result) ? Result::GetResult($result) : null; }
/** * Finds a group via its string name * * @param $group_string_name * * @return mixed|null */ public function FindGroup($group_string_name) { $result = Capsule::table('syscrack_permission_groups')->where('group_string_name', $group_string_name)->take(1)->get(); return !empty($result) ? Result::GetResult($result) : null; }
/** * Gets all the users in a group * * @param $group_id * * @return array|null */ public function GetRelatedUserGroups($group_id) { $result = Capsule::table('syscrack_users')->where('user_permission_group', $group_id)->get(); return !empty($result) ? Result::GetAllResults($result) : null; }
/** * Obtains a setting * * @param $setting_name * * @return array|bool|static[] */ public function ObtainSetting($setting_name) { $result = Capsule::table('syscrack_settings')->where('setting_name', $setting_name)->take(1)->get(); return !empty($result) ? Result::GetResultColumn($result, 'setting_value') : false; }
/** * Gets all the recent events * * @param $user_ip * * @param $recent_time * * @return array|bool|null */ public function GetRecentAttempts($user_ip, $recent_time) { $result = Capsule::table('syscrack_login_attempt')->where('attempted_user_ip', $user_ip)->orWhere('attempted_time', ">", $recent_time)->get(); return !empty($result) ? Result::GetAllResults($result) : false; }
/** * Gets all the sessions linked to that user * * @param $userid * * @return array|bool|null */ public function GetAllUserSessions($userid) { $result = Capsule::table('syscrack_active_sessions')->where('session_user_id', $userid)->get(); return !empty($result) ? Result::GetAllResults($result) : false; }
/** * Attempts a registration * * @param $username * * @param $password * * @param $email * * @param bool|true $return_token * * @return bool */ public function AttemptRegistration($username, $password, $email, $return_token = true) { if (SettingsManager::GetSetting('syscrack_allow_registration') == false) { /** * Add an error stating registration is disabled. */ ErrorBuilder::AddError("Sorry, Registration is disabled!"); /** * Return false; */ return false; } /** * If username is already taken */ if ($this->user->GetUserID($username) != null) { /** * Return an error is the username is taken */ ErrorBuilder::AddError("Sorry, this username is taken."); /** * Return false; */ return false; } /** * Lets now check all of our data */ if (StringChecker::CheckLength(5, $username) == false || StringChecker::CheckLength(5, $password) == false) { /** * Throw out an error */ ErrorBuilder::AddError("The data you entered is to small."); /** * Return false! */ return false; } /** * Username has special characters */ if (StringChecker::HasSpecialCharacters($username)) { /** * The username has special characters! */ ErrorBuilder::AddError("Your username has special characters."); /** * Return false */ return false; } /** * Password to weak */ if (StringChecker::GetScore($password) < 5) { /** * Password is far to weak! */ ErrorBuilder::AddError("Your password is to weak."); /** * Return false */ return false; } /** * Is this an email? */ if (StringChecker::IsEmail($email) == false) { /** * Its not an email */ ErrorBuilder::AddError("The email you entered is invalid."); /** * Return false */ return false; } /** * If the email already has an owner. */ if ($this->user->EmailOwner($email) != null) { /** * This email is already taken! */ ErrorBuilder::AddError("This email is already registered to an account, maybe you forgot your password?"); /** * Return false */ return false; } /** * If we have reached this point, everything is valid! Now lets generate a salt */ $salt = $this->GenerateSalt(); /** * Very important not to continue if the salt is null */ if ($salt != null) { /** * Great, we've now encrypted the password */ $encrypted_password = $this->EncryptPassword($password, $salt); /** * Another check, lets not continue if this is null! */ if ($encrypted_password != null) { /** * Lets now insert them into the database */ $this->user->Manager()->InsertUser($username, $encrypted_password, $salt, $email, $this->DefaultPermissionGroup()); /** * But, we are not done yet, this user cannot login until they have verified their email! Lets create a token for them! */ if ($this->user->GetUserID($username) != null) { /** * Lets get the user id */ $user_id = $this->user->GetUserID($username)['user_id']; /** * Lets make that request */ $result = $this->MakeVerifyRequest($user_id, $email); /** * We sent that email successfully */ if ($result == true) { /** * If we are set to return this access token (normally we are) */ if ($return_token) { /** * Gets the first row */ $row = Result::GetFirst($this->user->Email()->verify->GetVerifyAttempts($user_id)); /** * Return the token */ return $row['token_key']; } /** * Else, return true! */ return true; } else { /** * Error this user */ ErrorBuilder::AddError("We was unable to send you a verification email, please try again later"); /** * Delete them from the table (unable to verify) */ $this->user->Manager()->TrashUser($user_id); /** * Delete that verification attempt */ $this->user->Email()->verify->HasDeleteAttempts($user_id); /** * Return false */ return false; } } } } /** * An error occurred that we could not determine */ return false; }
/** * Gets this user ids tokens * * @param $user_id * * @return array|null */ public function GetVerifyAttempts($user_id) { $result = Capsule::table('syscrack_security_email_tokens')->where('token_user_id', $user_id)->get(); return !empty($result) ? Result::GetAllResults($result) : null; }
/** * Gets that hardware * * @param $hardware_id * * @return mixed|null */ public function GetHardware($hardware_id) { $result = Capsule::table('syscrack_game_hardware')->where('hardware_id', $hardware_id)->get(); return !empty($result) ? Result::GetResult($result) : null; }