Skip to content
Permalink
Browse files

Added proper facebook profile link

  • Loading branch information...
sergeychernyshev committed Mar 23, 2019
1 parent c40e642 commit 7611ebcee954e844066427b434aa186d2d130176
@@ -311,9 +311,8 @@ class ExistingUserException extends AuthenticationException {
* @var User|null Existing user or null if we just know that user exists, but did not get object specifically.
*/
private $existing_user;
public function __construct(User $user = null, $string, $code, $errors) {
parent::__construct($user, $string, $code, $errors);
public function __construct(User $user = null, $string = "User Alerady Exists", $code = 500, $errors = ["User Already Exists"]) {
parent::__construct($string, $code, $errors);
$this->existing_user = $user;
}
@@ -737,7 +737,7 @@ public function getAcceptedInvitations() {
*
* @throws DBException
*/
public static function createNewFacebookUser($name, $fb_id, $me = null) {
public static function createNewFacebookUser($name, $fb_id, $fb_link = null, $me = null) {
$name = mb_convert_encoding($name, 'UTF-8');
$db = UserConfig::getDB();
@@ -754,8 +754,8 @@ public static function createNewFacebookUser($name, $fb_id, $me = null) {
$user = null;
if ($stmt = $db->prepare("INSERT INTO u_users (name, regmodule, tos_version, email, fb_id) VALUES (?, 'facebook', ?, ?, ?)")) {
if (!$stmt->bind_param('sisi', $name, UserConfig::$currentTOSVersion, $email, $fb_id)) {
if ($stmt = $db->prepare("INSERT INTO u_users (name, regmodule, tos_version, email, fb_id, fb_link) VALUES (?, 'facebook', ?, ?, ?, ?)")) {
if (!$stmt->bind_param('sisis', $name, UserConfig::$currentTOSVersion, $email, $fb_id, $fb_link)) {
throw new DBBindParamException($db, $stmt);
}
if (!$stmt->execute()) {
@@ -2281,6 +2281,11 @@ private static function redirectToEmailVerification() {
*/
private $fbid;
/**
* @var string Facebook profile link
*/
private $fblink;
/**
* @var int Unix timestamp indicating user's registration time
*/
@@ -2308,18 +2313,20 @@ private static function redirectToEmailVerification() {
* @param string $email Email address
* @param boolean $requirespassreset Is this user required to reset their password
* @param int $fbid Facebook ID
* @param int $fblink Facebook profile link
* @param int $regtime Registration time
* @param int $points Total points user has
* @param boolean $is_email_verified Is user's email verified or not
*/
private function __construct($userid, $status = true, $name, $username = null, $email = null, $requirespassreset = false, $fbid = null, $regtime = null, $points = 0, $is_email_verified = false) {
private function __construct($userid, $status = true, $name, $username = null, $email = null, $requirespassreset = false, $fbid = null, $fblink = null, $regtime = null, $points = 0, $is_email_verified = false) {
$this->userid = $userid;
$this->status = $status ? true : false;
$this->name = $name;
$this->username = $username;
$this->email = $email;
$this->requirespassreset = $requirespassreset ? true : false;
$this->fbid = $fbid;
$this->fblink = $fblink;
$this->regtime = $regtime;
$this->points = $points;
$this->is_email_verified = $is_email_verified ? true : false;
@@ -2470,6 +2477,26 @@ public function setFacebookID($fbid) {
$this->fbid = $fbid;
}
/**
* Sets user's Facebook profile link
*
* You have to call save() method to persist to the database
*
* @param string $fblink User's Facebook profile link
*/
public function setFacebookProfileLink($fblink) {
$this->fblink = $fblink;
}
/**
* Returns user's Facebook profile link or null if user doesn't have a facebook account associated or link is not known
*
* @return string|null User's Facebook profile link
*/
public function getFacebookProfileLink() {
return $this->fblink;
}
/**
* Sets user's status - true if active and false if disabled
*
@@ -2657,8 +2684,8 @@ public function save() {
$name = is_null($this->name) || $this->name == '' ? null : mb_convert_encoding($this->name, 'UTF-8');
$email = is_null($this->email) || $this->email == '' ? null : mb_convert_encoding($this->email, 'UTF-8');
if ($stmt = $db->prepare('UPDATE u_users SET status = ?, username = ?, name = ?, email = ?, email_verified = ?, requirespassreset = ?, fb_id = ? WHERE id = ?')) {
if (!$stmt->bind_param('isssiiii', $status, $username, $name, $email, $email_verifiednum, $passresetnum, $this->fbid, $this->userid)) {
if ($stmt = $db->prepare('UPDATE u_users SET status = ?, username = ?, name = ?, email = ?, email_verified = ?, requirespassreset = ?, fb_id = ?, fb_link = ? WHERE id = ?')) {
if (!$stmt->bind_param('isssiiisi', $status, $username, $name, $email, $email_verifiednum, $passresetnum, $this->fbid, $this->fblink, $this->userid)) {
throw new DBBindParamException($db, $stmt);
}
if (!$stmt->execute()) {
@@ -19,6 +19,17 @@
$versions[_]['down'][] = "";
*/
/* -------------------------------------------------------------------------------------------------------
* VERSION 37
* Add fb_link field
*/
$versions[37]['up'][] = "ALTER TABLE `u_users` ADD COLUMN fb_link TEXT
CHARACTER SET utf8 COLLATE utf8_general_ci NULL
COMMENT 'Facebook profile link'
AFTER fb_id";
$versions[37]['down'][] = 'ALTER TABLE u_users DROP COLUMN `fb_link`';
/* -------------------------------------------------------------------------------------------------------
* VERSION 36
* corrected type
@@ -116,22 +116,22 @@ public function getUserCredentials($user) {
$userid = $user->getID();
if ($stmt = $db->prepare('SELECT fb_id FROM u_users WHERE id = ?')) {
if ($stmt = $db->prepare('SELECT fb_id, fb_link FROM u_users WHERE id = ?')) {
if (!$stmt->bind_param('i', $userid)) {
throw new DBBindParamException($db, $stmt);
}
if (!$stmt->execute()) {
throw new DBExecuteStmtException($db, $stmt);
}
if (!$stmt->bind_result($fb_id)) {
if (!$stmt->bind_result($fb_id, $fb_link)) {
throw new DBBindResultException($db, $stmt);
}
$stmt->fetch();
$stmt->close();
if (!is_null($fb_id)) {
return new FacebookUserCredentials($fb_id);
return new FacebookUserCredentials($fb_id, $fb_link);
}
} else {
throw new DBPrepareStmtException($db);
@@ -243,6 +243,7 @@ public function renderRegistrationForm($template_info, $full = false, $action =
*/
public function renderEditUserForm($template_info, $action, $errors, $user, $data) {
$fb_id = $user->getFacebookID();
$fb_link = $user->getFacebookProfileLink();
if (is_null($fb_id)) {
return $this->renderForm($template_info, $action, 'connect');
@@ -270,6 +271,7 @@ public function renderEditUserForm($template_info, $action, $errors, $user, $dat
$template_info['me'] = $me;
$template_info['fb_id'] = $fbuser_id;
$template_info['fb_link'] = $fb_link;
return StartupAPI::$template->render("@startupapi/modules/facebook/edit_user_form.html.twig", $template_info);
}
@@ -447,6 +449,7 @@ public function processRegistration($post_data, &$remember) {
$fbuser = $response->getGraphUser();
$fbuser_id = $fbuser->getId();
$fbuser_link = $fbuser["link"];
$me = $response->getDecodedBody();
$errors = array();
@@ -472,7 +475,7 @@ public function processRegistration($post_data, &$remember) {
// ok, let's create a user
try {
$user = User::createNewFacebookUser($name, $fbuser_id, $me);
$user = User::createNewFacebookUser($name, $fbuser_id, $fbuser_link, $me);
} catch (UserCreationException $e) {
$errors[$e->getField()][] = $e->getMessage();
}
@@ -489,6 +492,7 @@ public function processRegistration($post_data, &$remember) {
public function processEditUser($user, $data) {
if (array_key_exists('remove', $data)) {
$user->setFacebookID(null);
$user->setFacebookProfileLink(null);
$user->save();
$user->recordActivity(USERBASE_ACTIVITY_REMOVED_FB);
@@ -531,6 +535,7 @@ public function processEditUser($user, $data) {
$fbuser = $response->getGraphUser();
$fbuser_id = $fbuser->getId();
$fbuser_link = $fbuser["link"];
$me = $response->getDecodedBody();
$errors = array();
@@ -548,6 +553,7 @@ public function processEditUser($user, $data) {
}
$user->setFacebookID($fbuser_id);
$user->setFacebookProfileLink($fbuser_link);
// if user has email address and we required it for Facebook connection, let's save it
if (!$user->getEmail()) {
@@ -618,13 +624,20 @@ class FacebookUserCredentials extends UserCredentials {
*/
private $fb_id;
/**
* @var string Facebook profile link
*/
private $fb_link;
/**
* Creates credemtials onject
*
* @param int $fb_id Facebook user ID
* @param string $fb_link Facebook profile link
*/
public function __construct($fb_id) {
public function __construct($fb_id, $fb_link = null) {
$this->fb_id = $fb_id;
$this->fb_link = $fb_link;
}
/**
@@ -637,7 +650,7 @@ public function getFacebookID() {
}
public function getHTML() {
return StartupAPI::$template->render("@startupapi/modules/facebook/credentials.html.twig", array('fb_id' => $this->fb_id));
return StartupAPI::$template->render("@startupapi/modules/facebook/credentials.html.twig", array('fb_id' => $this->fb_id, 'fb_link' => $this->fb_link));
}
}
@@ -1 +1 @@
<a href="http://www.facebook.com/{{fb_id}}">{{fb_id}}</a>
{% if fb_link %}<a href="{{fb_link}}">{{fb_id}}</a>{% else %}{{fb_id}}{% endif %}

0 comments on commit 7611ebc

Please sign in to comment.
You can’t perform that action at this time.