コード例 #1
0
ファイル: post.php プロジェクト: EGreg/PHP-On-Pie
function users_register_post()
{
    $u = new Users_User();
    $u->email_address = $_REQUEST['email_address'];
    if ($u->retrieve()) {
        $key = 'this email';
        throw new Users_Exception_AlreadyVerified(compact('key'));
    }
    // Insert a new user into the database
    $user = new Users_User();
    $user->username = $_REQUEST['username'];
    if ($user->retrieve()) {
        throw new Users_Exception_UsernameExists(array(), array('username'));
    }
    $user->icon = 'default';
    $user->password_hash = '';
    $user->save();
    // sets the user's id
    // Import the user's icon
    if (isset($_REQUEST['icon'])) {
        $folder = 'user_id_' . $user->id;
        users_register_post_download($_REQUEST['icon'], $folder, 80);
        users_register_post_download($_REQUEST['icon'], $folder, 40);
        $user->icon = $folder;
        $user->save();
    }
    // Add an email to the user, that they'll have to verify
    $user->addEmail($_REQUEST['email_address']);
    Users::setLoggedInUser($user);
    Users::$cache['user'] = $user;
}
コード例 #2
0
ファイル: post.php プロジェクト: dmitriz/Platform
function Users_resend_post()
{
    $identifier = Users::requestedIdentifier($type);
    if ($type !== 'email' and $type !== 'mobile') {
        throw new Q_Exception("Expecting a valid email or mobile number", array('identifier', 'emailAddress', 'mobileNumber'));
    }
    if ($type === 'email') {
        $thing = 'email address';
        $field = 'emailAddress';
        $row = new Users_Email();
        $row->address = $identifier;
    } else {
        if ($type === 'mobile') {
            $thing = 'mobile number';
            $field = 'mobileNumber';
            $row = new Users_Mobile();
            $row->number = $identifier;
        } else {
            throw new Q_Exception("Expecting a valid email or mobile number", array('identifier', 'emailAddress', 'mobileNumber'));
        }
    }
    if ($row->retrieve()) {
        $userId = $row->userId;
    } else {
        if ($ui = Users::identify($type, $identifier, 'future')) {
            $userId = $ui->userId;
        } else {
            throw new Q_Exception("That {$thing} was not found in the system", array('identifier', $field));
        }
    }
    $user = new Users_User();
    $user->id = $userId;
    if (!$user->retrieve()) {
        throw new Q_Exception("No user corresponds to that {$thing}", array('identifier', $field));
    }
    if ($logged_in_user = Users::loggedInUser() and $logged_in_user->id != $user->id) {
        throw new Q_Exception("That {$thing} belongs to someone else", array('identifier', $field));
    }
    if ($type === 'email') {
        $existing = $user->addEmail($identifier);
    } else {
        $existing = $user->addMobile($identifier);
    }
    if ($existing) {
        $existing->resendActivationMessage();
    }
    Users::$cache['user'] = $user;
}