Example #1
0
 /**
  * Returns an existant user by email
  *
  * @return mixed
  */
 public static function getByEmail($email)
 {
     try {
         $c = new Criteria();
         $c->add(AuthUsersPeer::EMAIL, $email);
         $obj = AuthUsersPeer::doSelectOne($c);
         if (!$obj) {
             throw new Exception("There is no such user");
         }
         return array('id' => $obj->getId(), 'role' => $obj->getRole(), 'role_name' => $obj->getRole() ? $obj->getAuthRoles()->getName() : $obj->getRole(), 'email' => $obj->getEmail(), 'password' => $obj->getPassword(), 'user_status' => $obj->getUserStatus());
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Example #2
0
  /**
   * Returns a user by it's email
   *
   * @return mixed
   */
  public static function getByEmail ( $email )
  {
    try {
      $c = new Criteria;
      $c->add( AuthUsersPeer::EMAIL, $email );

      $obj = AuthUsersPeer::doSelectOne( $c );
      if ( !$obj ) {
        throw new Exception( 'There is no user email ' .$email );
      }

      return array( 'id' => $obj->getId(),
                    'role' => $obj->getRoleid(),
                    'email' => $obj->getEmail() );
    } catch ( Exception $e ) {
      return $e->getMessage();
    }
  }
  /**
   * Returns password and role by username and password
   *
   * @param TlalokesRequest $request
   * @return array
   */
  public function getUserRole ( TlalokesRequest &$request )
  {
    try {
      // validate username and password existance
      if ( !$request->email ) {
        throw new Exception( 'Provide an email' );
      }
      if ( !$request->password ) {
        throw new Exception( 'Provide a password' );
      }
      $response = array();

      // get permissions by auth method
      switch ( strtolower( $this->auth ) ) {

        case 'sql' :

          // set Criteria object
          $c = new Criteria();
          $c->add( AuthUsersPeer::EMAIL, $request->email );
          // do select
          $result = AuthUsersPeer::doSelectOne( $c );
          unset( $c );
          if ( !$result ) {
            throw new Exception( 'There are no coincidences' );
          }
          // set response
          $response = array( 'password' => $result->getPassword(),
                             'role' => $result->getRole() );
          break;

        case 'array' :

          break;
      }

      return $response;
    } catch ( Exception $e ) {
      return $e->getMessage();
    }
  }