/** * Checks to see if our email is verified * * @param $user_id * * @return bool */ public function IsEmailVerified($user_id) { /** * We will instantly return true if we are now using verified emails! */ if (SettingsManager::GetSetting('syscrack_security_email_require_verify') == false) { return true; } /** * If not, lets check their email */ if ($this->user->Manager()->GetUser($user_id) != null) { /** * Is our email verified? */ if ($this->user->EmailVerified($user_id)) { return true; } } return 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; }