Esempio n. 1
0
 public static function loginExternal($user_email, $provider_type)
 {
     $user = UserModel::getByEmail($user_email);
     if ($user) {
         $user_name = $user->getUsername();
         return self::login($user_name, null, null, $provider_type);
     } else {
         throw new \RuntimeException("loginExternal(): user is null");
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Handles the entire registration process for DEFAULT users (not for people who register with
  * 3rd party services, like facebook) and creates a new user in the database if everything is fine
  *
  * @return boolean Gives back the success status of the registration
  */
 public static function registerNewUser($user_name, $user_email, $user_email_repeat, $user_password_new, $user_password_repeat, $captcha, $provider_type)
 {
     $user_password_hash = null;
     $user_activation_hash = null;
     \Slim\Slim::getInstance()->log->debug("This is registerNewUser()");
     if (self::isDefaultProvider($provider_type)) {
         // stop registration flow if registrationInputValidation() returns false (= anything breaks the input check rules)
         $validation_result = self::registrationInputValidation($user_name, $user_password_new, $user_password_repeat, $user_email, $user_email_repeat, $captcha);
         if (!$validation_result) {
             \Slim\Slim::getInstance()->log->debug("ERROR: registrationInputValidation() failed");
             return false;
         }
         \Slim\Slim::getInstance()->log->debug("OK: registrationInputValidation() returns true");
         // crypt the password with the PHP 5.5's password_hash() function, results in a 60 character hash string.
         // @see php.net/manual/en/function.password-hash.php for more, especially for potential options
         $user_password_hash = password_hash($user_password_new, PASSWORD_DEFAULT);
         \Slim\Slim::getInstance()->log->debug("\$user_password_hash: " . $user_password_hash);
         if (\Slim\Slim::getInstance()->config('auth.email.verification.enabled')) {
             // generate random hash for email verification (40 char string)
             $user_activation_hash = sha1(uniqid(mt_rand(), true));
         }
     }
     // check if username already exists
     if (User::getByUsername($user_name) !== null) {
         \Slim\Slim::getInstance()->log->debug("Error: Username non disponibile");
         Session::add(Session::SESSION_FEEDBACK_NEGATIVE, Text::get('FEEDBACK_USERNAME_ALREADY_TAKEN'));
         return false;
     }
     \Slim\Slim::getInstance()->log->debug("OK: username doesn't exists");
     // check if email already exists
     if (User::getByEmail($user_email) !== null) {
         \Slim\Slim::getInstance()->log->debug('Email in uso');
         Session::add(Session::SESSION_FEEDBACK_NEGATIVE, Text::get('FEEDBACK_USER_EMAIL_ALREADY_TAKEN'));
         return false;
     }
     \Slim\Slim::getInstance()->log->debug("OK: email doesn't exists");
     // write user data to database
     if (!self::writeNewUserToDatabase($user_name, $user_password_hash, $user_email, $user_activation_hash, $provider_type)) {
         \Slim\Slim::getInstance()->log->debug('Registrazione fallita');
         Session::add(Session::SESSION_FEEDBACK_NEGATIVE, Text::get('FEEDBACK_ACCOUNT_CREATION_FAILED'));
         return false;
     }
     \Slim\Slim::getInstance()->log->debug("OK: writeNewUserToDatabase() returns true");
     $user = User::getByEmail($user_email);
     // get user_id of the user that has been created
     if (!$user) {
         Session::add(Session::SESSION_FEEDBACK_NEGATIVE, Text::get('FEEDBACK_UNKNOWN_ERROR'));
         return false;
     }
     if (self::isDefaultProvider($provider_type) && \Slim\Slim::getInstance()->config('auth.email.verification.enabled')) {
         // send verification email
         if (self::sendVerificationEmail($user_name, $user_email, $user_activation_hash)) {
             \Slim\Slim::getInstance()->log->debug("OK: verification email sent to " . $user_email);
             Session::add(Session::SESSION_FEEDBACK_POSITIVE, Text::get('FEEDBACK_ACCOUNT_SUCCESSFULLY_CREATED'));
             return true;
         }
         \Slim\Slim::getInstance()->log->debug("ERROR: sending verification email to " . $user_email . " failed");
         // if verification email sending failed: instantly delete the user
         self::rollbackRegistrationByUsername($user_name);
         \Slim\Slim::getInstance()->log->debug("NOTICE: rollbackRegistrationByUsername()");
         Session::add(Session::SESSION_FEEDBACK_NEGATIVE, Text::get('FEEDBACK_VERIFICATION_MAIL_SENDING_FAILED'));
         return false;
     } else {
         if (self::sendWelcomeEmail($user_name, $user_email)) {
             return true;
         }
         \Slim\Slim::getInstance()->log->debug("ERROR: sending welcome email to " . $user_email . " failed");
         Session::add(Session::SESSION_FEEDBACK_NEGATIVE, Text::get('FEEDBACK_WELCOME_MAIL_SENDING_FAILED'));
         return false;
     }
     return false;
 }
Esempio n. 3
0
 private static function registerOrMergeNewUserDefault($fb_graph_user)
 {
     $user = null;
     if ($fb_graph_user) {
         $fb_email = $fb_graph_user->getEmail();
         $user = UserModel::getByEmail($fb_email);
         if ($user) {
             // Allora esiste già un utente con la stessa email
             // Merge dell'account esistente con i dati FB
             //
             // Nota che le situazioni critiche sono due
             // 1) L'utente esiste già nella tabella User ma non in quella UserExternal
             // 2) L'utente esiste già in entrambe le tabelle ma con 'provider' differente
             IubarFattureApp::getInstance()->log->debug("registerOrMergeNewUserDefault(): calling self::mergeAccount()");
             $b = self::mergeAccount($user, $fb_graph_user);
         } else {
             // Creo l'utente standard...;
             $fb_id = $fb_graph_user->getId();
             IubarFattureApp::getInstance()->log->debug("registerOrMergeNewUserDefault(): calling ExternalModel::registerNewUserDefault()");
             $b = ExternalModel::registerNewUserDefault($fb_id, $fb_email, UserModel::PROVIDER_TYPE_FB);
         }
     } else {
         // error
     }
     return $b;
 }