Created
October 4, 2018 13:02
-
-
Save cosmos-sajal/f385f0d3a6324cfe893b781d4daf7e58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Post("/magic_link_signup") | |
*/ | |
function magicLinkSignUp($request) { | |
// get the query parameters from the post request | |
$queryParams = $request->query()->all(); | |
// get the token from queryParams | |
// this $token is the same $randomString that was | |
// generated in Step 1 | |
$token = $queryParamas['token']; | |
// use the same function as in Step 1 to generate | |
// hashed value of the $randomString | |
$maskedRandomString = generateMaskedRandomString($token); | |
// query the database to get the information regarding | |
// this $maskedRandomString | |
$magicLink = (select * from magic_links | |
where masked_random_string = $maskedRandomString); | |
$mobileNumber = $magicLink['mobile_number']; | |
$targetURL = $magicLink['target_screen']; | |
// get the user info of this mobile_number from your | |
// user's database table | |
$userInfo = (select * from users where | |
mobile_number = $mobileNumber); | |
// if the user doesn't exist, create one in | |
// the users table of your database | |
// now create session for this User | |
setSession($userInfo); | |
// set cookies (if any) for this User | |
setCookies($userInfo); | |
// now redirect the user with logged in | |
// session and set cookies to the target screen | |
redirect($targetURL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment