Example #1
0
 public function testGetUsername()
 {
     $this->User->setUsername('testuser');
     if ($this->User->getUsername() != 'testuser') {
         $this->fail();
     }
 }
Example #2
0
 public function LoginUser(User $user, $web)
 {
     $this->username = $_SESSION[self::$sessionUsername] = $user->getUsername();
     $_SESSION[self::$sessionUserHeadCategory][self::$sessionUsername] = $user->getUsername();
     $_SESSION[self::$securitySessionName] = hash(self::$hashString, $web);
     $this->isLoggedIn = true;
 }
Example #3
0
 /**
  * Summary of execute
  * @param \DOMElement $apiDocument
  * @return \DOMElement
  * @throws ApiException
  * @throws \Exception
  */
 public function execute(\DOMElement $apiDocument)
 {
     $username = isset($_GET['user']) ? trim($_GET['user']) : '';
     $wikiusername = isset($_GET['wikiuser']) ? trim($_GET['wikiuser']) : '';
     if ($username === '' && $wikiusername === '') {
         throw new ApiException("Please specify a username using either user or wikiuser parameters.");
     }
     $userElement = $this->document->createElement("user");
     $apiDocument->appendChild($userElement);
     $this->database = gGetDb();
     if ($username !== '') {
         $this->user = \User::getByUsername($username, $this->database);
     } else {
         $this->user = \User::getByOnWikiUsername($wikiusername, $this->database);
     }
     if ($this->user === false) {
         $userElement->setAttribute("missing", "true");
         return $apiDocument;
     }
     $userElement->setAttribute("username", $this->user->getUsername());
     $userElement->setAttribute("status", $this->user->getStatus());
     $userElement->setAttribute("lastactive", $this->user->getLastActive());
     $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate());
     $userElement->setAttribute("onwikiname", $this->user->getOnWikiName());
     $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false");
     return $apiDocument;
 }
Example #4
0
function userLogin($username, $password, $log = true)
{
    global $USER, $MSG;
    if ($username == "") {
        array_push($MSG, getstring('warning.login.noemail'));
        return false;
    }
    if ($password == "") {
        array_push($MSG, getstring('warning.login.nopassword'));
        return false;
    }
    $USER = new User($username);
    $USER->setUsername($username);
    $USER->password = $password;
    if ($USER instanceof User) {
        if ($USER->validPassword($password)) {
            $_SESSION["session_username"] = $USER->getUsername();
            setcookie("user", $USER->getUsername(), time() + 60 * 60 * 24 * 30, "/");
            setLang($USER->getProp('lang'));
            if ($log) {
                writeToLog('info', 'login', 'user logged in');
            }
            return true;
        } else {
            array_push($MSG, getstring('warning.login.invalid'));
            writeToLog('info', 'loginfailure', 'username: ' . $username);
            unset($USER);
            return false;
        }
    } else {
        return false;
    }
}
 public function testUsername()
 {
     $usernameTest = "Jorge";
     $this->assertEmpty($this->user->getUsername());
     $this->user->setUsername($usernameTest);
     $this->assertEquals($usernameTest, $this->user->getUsername());
 }
Example #6
0
 public function LoginUser(User $user)
 {
     global $remote_ip;
     global $user_agent;
     $this->username = $_SESSION[self::$sessionUsername] = $user->getUsername();
     $_SESSION[self::$sessionUserHeadCategory][self::$sessionUsername] = $user->getUsername();
     $_SESSION[self::$securitySessionName] = hash(self::$hashString, $remote_ip . $user_agent);
     $this->isLoggedIn = true;
 }
Example #7
0
 public function __construct()
 {
     $this->view = ViewManager::getInstance();
     // get the current user and put it to the view
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
     if (isset($_SESSION["currentuser"])) {
         $this->currentUser = new User($_SESSION["currentuser"]);
         //add current user to the view, since some views require it
         $this->view->setVariable("currentusername", $this->currentUser->getUsername());
     }
 }
Example #8
0
function email_plugin_notify_master($check, $check_result, $subscription, $alt_email = false)
{
    global $status_array;
    $user = new User($subscription->getUserId());
    $email = new fEmail();
    // This sets up fSMTP to connect to the gmail SMTP server
    // with a 5 second timeout. Gmail requires a secure connection.
    $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), sys_var('require_ssl') === 'true' ? TRUE : FALSE, 5);
    if (sys_var('require_auth') === 'true') {
        $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass'));
    }
    if ($alt_email) {
        $email_address = usr_var('alt_email', $user->getUserId());
    } else {
        $email_address = $user->getEmail();
    }
    $email->addRecipient($email_address, $user->getUsername());
    // Set who the email is from
    $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display'));
    $state = $status_array[$check_result->getStatus()];
    // Set the subject include UTF-8 curly quotes
    if ($state == 'OK') {
        $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_end_alert_subject')));
    } else {
        $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject')));
    }
    // Set the body to include a string containing UTF-8
    $check_type = '';
    if ($check->getType() == 'threshold') {
        $check_type = ' Threshold';
    } elseif ($check->getType() == 'predictive') {
        $check_type = ' Standard Deviation';
    }
    $state_email_injection = $state . " Alert ";
    if ($state == 'OK') {
        $state_email_injection = "Everything's back to normal ";
    }
    // Remind : ('0' => 'OK', '1'   => 'Error', '2' => 'Warning');
    $state_int = $check_result->getStatus();
    if ($state_int == 0) {
        $color = "green";
    } else {
        if ($state_int == 2) {
            $color = "orange";
        } else {
            $color = "red";
        }
    }
    $html_body = "<p style='color:" . $color . ";'>" . $state_email_injection . "for {$check->prepareName()} </p>" . "<p>The check returned {$check_result->getValue()}</p>" . "<p>Warning" . $check_type . " is : " . $check->getWarn() . "</p>" . "<p>Error" . $check_type . " is : " . $check->getError() . "</p>" . "<p>View Alert Details : <a href='" . $GLOBALS['TATTLE_DOMAIN'] . '/' . CheckResult::makeURL('list', $check_result) . "'>" . $check->prepareName() . "</a></p>";
    $email->setHTMLBody($html_body);
    $email->setBody("\n  {$state} Alert for {$check->prepareName()}\nThe check returned {$check_result->getValue()}\nWarning" . $check_type . " is : " . $check->getWarn() . "\nError" . $check_type . " is : " . $check->getError() . "\n           ");
    try {
        $message_id = $email->send($smtp);
    } catch (fConnectivityException $e) {
        fCore::debug($e, FALSE);
        fCore::debug("email send failed", FALSE);
        $e->printMessage();
        $e->printTrace();
    }
}
Example #9
0
 function login()
 {
     $code = '';
     if (isset($_GET['code'])) {
         $code = $_GET['code'];
     }
     if (!isset($_SESSION)) {
         session_start();
     }
     $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . FB_APP . "&redirect_uri=" . urlencode(FB_URL) . "&client_secret=" . FB_SECRET . "&code=" . $code;
     $response = file_get_contents($token_url);
     $params = null;
     parse_str($response, $params);
     $_SESSION['access_token'] = $params['access_token'];
     $graph_url = "https://graph.facebook.com/me?access_token=" . $_SESSION['access_token'];
     $fb_user = json_decode(file_get_contents($graph_url));
     $user = new User();
     //adding the fb_id to the existing email and login
     if (!$user->checkLogin($fb_user->email)) {
         $user->id = $user->getIDByEmail($fb_user->email);
         $user->username = $user->getUsername();
         $user->addFBID($fb_user->id);
         $user->fb_id = $fb_user->id;
         $auth = new SlideWikiAuth($user);
         $auth->login();
         echo "<script> top.location.href='" . BASE_PATH . "'</script>";
     } else {
         $this->set('fb_user', $fb_user);
     }
 }
function verifyCredentials($username, $password)
{
    $loginDB = new LoginDB();
    $user = null;
    $users = array();
    $res = $loginDB->getAccount($username);
    while ($users = $res->fetch_object()) {
        if ($users->Username == null) {
            exit;
        }
        $dbUsername = $users->Username;
        $dbPassword = $users->Password;
        $dbRoleId = $users->Role_ID;
        $dbCostumerId = $users->Costumer_ID;
        $user = new User($dbUsername);
        $user->setPassword($dbPassword);
        $user->setRoleId($dbRoleId);
        $user->setCostumerId($dbCostumerId);
    }
    if ($user != null) {
        if (strtolower($user->getUsername()) == strtolower($username) && $user->getPassword() == $password) {
            $_SESSION["user"] = $user;
            header("Location: ../index.php");
        }
    }
}
Example #11
0
function email_plugin_notify($check,$check_result,$subscription,$alt_email=false) {
  global $status_array;
  $user = new User($subscription->getUserId());
  $email = new fEmail();
  // This sets up fSMTP to connect to the gmail SMTP server
  // with a 5 second timeout. Gmail requires a secure connection.
  $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), TRUE, 5);
  $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass'));
  if ($alt_email) {
    $email_address = usr_var('alt_email',$user->getUserId());
  } else {
    $email_address = $user->getEmail(); 
  }
  $email->addRecipient($email_address, $user->getUsername());
  // Set who the email is from
  $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display'));
  // Set the subject include UTF-8 curly quotes
  $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject')));
  // Set the body to include a string containing UTF-8
  $state = $status_array[$check_result->getStatus()];
  $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>");
  $email->setBody("
  $state Alert for {$check->prepareName()}
The check returned {$check_result->prepareValue()}
Warning Threshold is : ". $check->getWarn() . "
Error Threshold is : ". $check->getError() . "
           ");
  try {  
    $message_id = $email->send($smtp);
  } catch ( fConnectivityException $e) { 
    fCore::debug("email send failed",FALSE);
  }
}
Example #12
0
 /**
  * Set a valid cookie for a user.
  */
 public static function setCookies(User $user)
 {
     $config = Config::getInstance();
     $expire = time() + 60 * 60 * 24 * (int) $config->cookieDays;
     setcookie('username', $user->getUsername(), $expire, '/', $config->domain);
     setcookie('passhash', $user->getPasshash(), $expire, '/', $config->domain);
 }
Example #13
0
function email_notify($check,$check_result,$subscription) {
 global $status_array;
 $user = new User($subscription->getUserId());
 echo 'email plugin!';
 $email = new fEmail();
 // This sets up fSMTP to connect to the gmail SMTP server
 // with a 5 second timeout. Gmail requires a secure connection.
 $smtp = new fSMTP('smtp.gmail.com', 465, TRUE, 5);
 $smtp->authenticate('*****@*****.**', 'example');
 $email->addRecipient($user->getEmail(), $user->getUsername());
 // Set who the email is from
 $email->setFromEmail('*****@*****.**','Tattle');
 // Set the subject include UTF-8 curly quotes
 $email->setSubject('Tattle : Alert for ' . $check->prepareName());
 // Set the body to include a string containing UTF-8
 $state = $status_array[$check_result->getStatus()];
 $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . $fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>");
 $email->setBody("
$state Alert for {$check->prepareName()}
The check returned {$check_result->prepareValue()}
Warning Threshold is : ". $check->getWarn() . "
Error Threshold is : ". $check->getError() . "
           ");
 try {  
   $message_id = $email->send($smtp);
 } catch ( fConnectivityException $e) { 
   fCore::debug("email send failed",FALSE);
 }


}
 public function test_login()
 {
     $user = new User();
     $this->_assert_equals($user->login(self::USERNAME, self::PASSWORD), SUCCESSFULLY);
     $this->_assert_equals($this->session->userdata("type"), STUDENT_TYPE);
     $this->_assert_equals($user->getUsername(), self::USERNAME);
 }
Example #15
0
 function profile()
 {
     $id = $_GET['id'];
     $user = new User();
     $user->id = $id;
     $user->getUsername();
     //show error if user does not exist
     if (!isset($user->username)) {
         header('Location: ' . BASE_PATH . 'error/404');
         die;
     }
     $user->createFromIDFull($id);
     $email = $user->getEmail();
     $user->subscriptions = $user->getSubscriptions();
     if ($this->_user['id']) {
         $current_user = new User();
         $current_user->createFromID($this->_user['id']);
         $current_user->subscriptions = $current_user->getSubscriptions();
         $this->set('isFollowing', $current_user->isFollowing('user', $id));
     } else {
         $this->set('isFollowing', 0);
     }
     $this->set('profile', $user);
     $this->set('email', $email);
     $this->set('login_user', $this->_user['id']);
     $this->set('page_title', "SlideWiki User - " . $user->username);
     $this->set('page_description', $user->description);
     $this->set('page_additional_footer', '<p><a href="user/alldecks/' . $user->id . '">( "' . $user->username . '"  plain decks )</a></p>');
 }
 /**
  * @param \Symfony\Component\Form\Form $form
  * @param \AppBundle\Entity\User $user
  * @return boolean
  */
 public function createUser(Form $form, User $user) : bool
 {
     if ($user->getUsername() === 'Toto') {
         $form->get('username')->addError(new FormError('users.registration.username_already_taken'));
         return false;
     }
     return true;
 }
 /**
  * Get username of the creator of the notification
  * @return mixed
  */
 public function getUsername()
 {
     require_once "User.php";
     # Get the user object
     $user = new User($this->CreatorUserId);
     # Return hers/his username
     return $user->getUsername();
 }
Example #18
0
 public function equals(User $user)
 {
     if (strcmp($this->username, $user->getUsername()) == 0 && strcmp($this->password, $user->getPassword()) == 0 && ($this->id == $user->getId()) == TRUE) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
Example #19
0
 /**
  * @return User
  */
 public function getUser()
 {
     if (!$this->user && $this->userId) {
         $this->user = User::getById($this->userId);
         $this->setUsername($this->user->getUsername());
     }
     return $this->user;
 }
Example #20
0
 public function addUser(User $user)
 {
     $username = $user->getUsername();
     $password = $user->getPasswordHash();
     $username = mysqli_escape_string($this->conn, $username);
     $password = mysqli_escape_string($this->conn, $password);
     mysqli_query($this->conn, "INSERT INTO member (Username, Password) VALUES ('{$username}', '{$password}')");
 }
Example #21
0
 /**
  * A method to return the username of the creator of the nate
  * @return String the username
  */
 function getUsername()
 {
     require_once 'User.php';
     # Get the user object
     $user = new User($this->UserId);
     # Return his/hers username
     return $user->getUsername();
 }
Example #22
0
 public function login(\User $user)
 {
     $query = "SELECT *from user where User_Name='" . $user->getUsername() . "' and User_Password='******'";
     $userExit = $this->conn->query($query);
     if ($userExit) {
         return true;
     }
     return false;
 }
Example #23
0
 /**
  * @return User
  */
 public function getUser()
 {
     if (!$this->user && $this->userId) {
         $this->user = User::getById($this->userId);
         if ($this->user instanceof User) {
             $this->setUsername($this->user->getUsername());
         }
     }
     return $this->user;
 }
Example #24
0
 public function testSetGetUsername()
 {
     // Arrange
     $user = new User();
     $user->setUsername('john');
     $expectedResult = 'john';
     // Act
     $result = $user->getUsername();
     // Assert
     $this->assertEquals($result, $expectedResult);
 }
Example #25
0
 public function add(User $toBeAdded)
 {
     $stmt = $this->database->prepare("INSERT INTO  `a9523293_mirza`.`users` (\n\t\t\t`username` , `password`)\n\t\t\t\tVALUES (?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($this->database->error);
     }
     $usern = $toBeAdded->getUsername();
     $pass = $toBeAdded->getPassword();
     $stmt->bind_param('ss', $usern, $pass);
     $stmt->execute();
 }
Example #26
0
 public function updateUser(User $user)
 {
     $existingUser = $this->getUserById($user->getId());
     if ($user->getRole()->getId() != $existingUser->getRole()->getId() && $this->isRootUser($existingUser)) {
         throw new AemosRestException(AppLabelUtil::$ERROR_USER_IS_ROOT, HttpStatusCode::badRequest());
     }
     ResultHelper::whenEmpty($user->getUsername(), AppLabelUtil::$ERROR_USER_INCOMPLETE, HttpStatusCode::badRequest());
     ResultHelper::whenEmpty($user->getEmail(), AppLabelUtil::$ERROR_USER_INCOMPLETE, HttpStatusCode::badRequest());
     ResultHelper::whenEmpty($user->getRole(), AppLabelUtil::$ERROR_USER_INCOMPLETE, HttpStatusCode::badRequest());
     $this->userDao->update($user);
 }
 /**
  * @test
  */
 public function testUserProperties()
 {
     $uid = '123';
     $nick = 'test';
     $email = '*****@*****.**';
     $user = new User($uid, $nick, $email);
     $this->assertEquals($nick, $user->getUsername());
     $this->assertEquals(null, $user->getSalt());
     $this->assertEquals(array('ROLE_USER'), $user->getRoles());
     $this->assertEquals('', $user->getPassword());
 }
Example #28
0
 /**
  * Add user to the database.
  * 
  * @param \model\User $user The user to be added to the database
  */
 public function add(User $user)
 {
     $sqli = $this->database->connect();
     $stmt = $sqli->prepare("INSERT INTO `users`(`username`, `password`) VALUES (?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($sqli->error);
     }
     $username = $user->getUsername();
     $password = $user->getPassword();
     $stmt->bind_param('ss', $username, $password);
     $stmt->execute();
 }
Example #29
0
 public function addNewUser(User $user)
 {
     try {
         $pdo = $this->connectionToDataBase();
         $sql = "INSERT INTO {$this->tabel}    \n\t\t\t\t(" . self::$username . ", " . self::$password . ")\n\t\t\t\tVALUES(?,?)";
         $params = array($user->getUsername(), $user->getPasswrod());
         $query = $pdo->prepare($sql);
         $query->execute($params);
     } catch (PDOException $ex) {
         die('An unknown error has happened jebla');
     }
 }
Example #30
0
 /**
  * Add user to the database.
  * User for registration.
  *
  * @param \model\User $user The user to be added to the database
  */
 public function add(User $user)
 {
     $sqli = $this->database->connect();
     $stmt = $sqli->prepare("INSERT INTO " . $this->table . "(" . $this->usernameCol . ", " . $this->passwordCol . ", " . $this->profileinfoCol . ") VALUES (?, ?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($sqli->error);
     }
     $username = $user->getUsername();
     $password = $user->getPassword();
     $profileinfo = $user->getProfile();
     $stmt->bind_param('sss', $username, $password, $profileinfo);
     $stmt->execute();
 }