Пример #1
0
function __reserve_verification($user_id, $verification_type)
{
    $verification = Verification::where('user_id', $user_id)->where('verification_type', $verification_type)->first();
    if ($verification == NULL) {
        $verification = new Verification();
        $verification->user_id = $user_id;
        $verification->verification_type = $verification_type;
    }
    $verification->verification_code = substr(md5($user_id . date('Y-m-d H:i:s')), 0, 5);
    $verification->save();
    if ($verification_type == 'phone') {
        $sid = "SKe44ed0bc0d4fe3aa1522d2a44a7af704";
        // Your Account SID from www.twilio.com/user/account
        $token = "bga6bpnuSSWb1HNLq1yvonTowBqZaqwK";
        // Your Auth Token from www.twilio.com/user/account
        $content = 'Use code ' . $verification->verification_code . ' for verification.';
        $user = User::find($user_id);
        $account_sid = 'AC9937d29c6659b015a408cf849e5aa611';
        $auth_token = '5ecc8903da4ad3913e380025f75a82b3';
        $client = new Services_Twilio($account_sid, $auth_token);
        $client->account->messages->create(array('To' => $user->phone, 'From' => "+18559729840", 'Body' => $content));
    } else {
        if ($verification_type == 'email') {
            $user = User::find($user_id);
            $content = 'Use this code <b>' . $verification->verification_code . '</b> for verification.';
            sendEmail($user->email, 'User Email Verification', $content);
        }
    }
}