Файл: Source/auth/finish-signup.php
Строк: 76
<?php
$config = require_once( "config.php" );
require_once( "Social/Auth.php" );
$socialAuth = new Social_Auth( $config );
/**
* This part is for email check. For example, after twitter auth for first time signup, we are promting
* user for email. When save clicked, we are checking email existance
*/
if (!empty($_POST["check_email"])) {
$user = Social_Auth::dao()->getUserByEmailAndNetwork($_POST["check_email"], $_POST["network"]);
if ($user) {
$res = array(
"response" => "Email already exists",
"result" => false
);
} else {
$socialAuth->authenticate( $_POST["network"] );
$network = $socialAuth->getAdapter($_POST["network"]);
$user_profile = $network->getUserProfile();
$user_profile->email = $_POST["check_email"];
Social_Auth::dao()->saveUserSocial($user_profile, $_POST["network"]);
$res = array(
"response" => "success",
"result" => true
);
$userInfo = Social_Auth::dao()->getUserByUsernameOrEmail($_POST["check_email"]);
Social_Auth::session()->set("SA_USER", $userInfo);
}
/**
* Forgot password section
*/
} elseif (!empty($_POST["forgot_password"])) {
$user = Social_Auth::dao()->getUserByUsernameOrEmail($_POST["forgot_email"]);
if ($user) {
$pass = Social_Auth::dao()->randomString();
$md5 = md5( $pass );
$resetResult = Social_Auth::dao()->resetPassword($_POST["forgot_email"], $md5);
if ($resetResult) {
$to = $_POST["forgot_email"];
$subject = 'Password Reset';
$message = 'hello';
$headers = 'From: socialauth@huseyinbabal.net' . "rn" .
'Reply-To: webmaster@example.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
$message = "Hi,nYour new password is: " . $pass . "n";
mail($to, $subject, $message, $headers);
}
}
$res = array(
"response" => "If your email is registered, we have sent you a new password",
"result" => true
);
/**
* Normal signup
*/
} elseif (!empty($_POST["signup"])) {
$username = $_POST["username"];
$email = $_POST["signup_email"];
$password1 = $_POST["password1"];
$password2 = $_POST["password2"];
$checkEmail = Social_Auth::dao()->getUserByUsernameOrEmail($email);
$checkUsername = Social_Auth::dao()->getUserByUsernameOrEmail($username);
if ($checkEmail) {
$res = array(
"response" => "Email already exists",
"result" => false
);
} else if ($checkUsername) {
$res = array(
"response" => "Username already exists",
"result" => false
);
} else {
Social_Auth::dao()->signupUser($email, $password1, $username);
$userCheck = Social_Auth::dao()->getUserByemailAndPassword($email, $password1);
Social_Auth::session()->set( "SA_USER", $userCheck );
$res = array(
"response" => "Sucessfully registered!",
"result" => true
);
}
// Normal login
} elseif (!empty($_POST["login"])) {
$email = $_POST["email"];
$password = $_POST["password"];
$userCheck = Social_Auth::dao()->getUserByemailAndPassword($email, $password);
if ($userCheck) {
Social_Auth::session()->set( "SA_USER", $userCheck );
$res = array(
"response" => "Successfully logged in",
"result" => true
);
} else {
$res = array(
"response" => "Login failed",
"result" => false
);
}
} else {
$res = array(
"response" => "Direct access is not allowed",
"result" => false
);
Social_Logger::error( "Direct access not allowed in finish-signup without any params" );
}
echo json_encode($res);