/**
  * Invitation form and processing of invited user details
  */
 public function actionIndex($p)
 {
     if ($this->request->isPost()) {
         $firstName = Fari_Decode::accents($this->request->getPost('first'));
         $lastName = Fari_Decode::accents($this->request->getPost('last'));
         $email = $this->request->getPost('email');
         if (!Fari_Filter::isEmail($email) or empty($firstName)) {
             $this->bag->message = array('status' => 'fail', 'message' => 'Whoops, make sure you enter a full name and proper email address.');
             $this->bag->first = $this->request->getRawPost('first');
             $this->bag->last = $this->request->getRawPost('last');
             $this->bag->email = $this->request->getRawPost('email');
         } else {
             $name = $this->accounts->newInvitation($firstName, $lastName, $email);
             // mail the instructions
             $mail = new Mailer();
             try {
                 $mail->sendInvitation();
             } catch (UserNotFoundException $e) {
                 $this->redirectTo('/error404/');
             }
             $this->flashSuccess = "{$name} is now added to your account. An email with instructions was sent to {$email}";
             $this->redirectTo('/users/');
         }
     }
     $this->bag->tabs = $this->user->inRooms();
     $this->renderAction('new');
 }
예제 #2
0
 /**
  * User sign-in/login
  */
 public function actionLogin()
 {
     // authenticate user if form data POSTed
     if ($this->request->getPost('username')) {
         $username = Fari_Decode::accents($this->request->getPost('username'));
         $password = Fari_Decode::accents($this->request->getPost('password'));
         try {
             $this->user = new UserLogin($username, $password, $this->request->getPost('token'));
         } catch (UserNotAuthenticatedException $e) {
             $this->flashFail = 'Sorry, your username or password wasn\'t recognized';
         }
         $this->redirectTo('/');
     }
     // create token & display login form
     $this->bag->token = Fari_FormToken::create();
     $this->renderAction();
 }
예제 #3
0
 public function actionLogin()
 {
     // authenticate user if form data POSTed
     if ($this->request->getPost('username')) {
         $username = Fari_Decode::accents($this->request->getPost('username'));
         $password = Fari_Decode::accents($this->request->getPost('password'));
         $this->user = new Fari_AuthenticatorSimple();
         if ($this->user->authenticate($username, $password, $this->request->getPost('token'))) {
             $this->redirectTo('/');
         } else {
             $this->flashFail = 'Sorry, your username or password wasn\'t recognized';
         }
     }
     $this->flashNotify = 'Use \'admin\' for username and password.';
     // create token & display login form
     $this->bag->token = Fari_FormToken::create();
     $this->renderAction();
 }
예제 #4
0
 /**
  * User sign-in/login
  */
 public function actionLogin()
 {
     // authenticate user if form data POSTed
     if ($this->request->getPost('username')) {
         $username = Fari_Decode::accents($this->request->getPost('username'));
         $password = Fari_Decode::accents($this->request->getPost('password'));
         try {
             $user = new AuthAuth($username, $password, $this->request->getPost('token'));
             // redirect us to the route originally requested
             if (isset($_SESSION['Route'])) {
                 $route = $_SESSION['Route'];
                 unset($_SESSION['Route']);
                 $this->redirectTo($route);
             } else {
                 $this->redirectTo('/' . self::ADMIN);
             }
         } catch (AuthUserNotAuthenticatedException $e) {
             $this->flashFail = "Sorry, your username or password wasn't recognized";
         }
     }
     // create token & display login form
     $this->bag->token = Fari_FormToken::create();
     $this->renderAction('login');
 }
예제 #5
0
 /**
  * Generate a slug from a text (e.g., "Červený 'nejede'!" will turn into "cerveny-nejede").
  *
  * @param string $input
  * @return string
  */
 public static function slug($input)
 {
     return preg_replace("/\\s+/", "-", preg_replace("/[^a-zA-Z0-9 ]/", "", strtolower(Fari_Decode::accents($input))));
 }
예제 #6
0
 /**
  * Get code and name from the form and create a new user for us (generate username)
  */
 public function actionCreate()
 {
     $name = Fari_Decode::accents($this->request->getPost('name'));
     $code = $this->request->getPost('code');
     if (!empty($name)) {
         $name = explode(' ', $name);
         // do we have a 'long' name?
         if (count($name) > 1) {
             $short = $name[0] . ' ' . substr(end($name), 0, 1) . '.';
             $long = implode(' ', $name);
             $surname = end($name);
             $name = $name[0];
         } else {
             $short = $long = $name = $name[0];
             $surname = '';
         }
         // generate a username
         $username = Fari_Escape::slug($long) . Fari_Tools::randomCode(10);
         $db = Fari_Db::getConnection();
         // insert the user in a guest role
         $userId = $db->insert('users', array('short' => $short, 'long' => $long, 'name' => $name, 'surname' => $surname, 'role' => 'guest', 'username' => $username));
         // log them in automatically
         Fari_AuthenticatorSimple::forceAuthenticate($username);
         // give them permissions to enter this room
         $room = $db->selectRow('rooms', 'id', array('guest' => $code));
         if (!empty($room)) {
             $db->insert('user_permissions', array('room' => $room['id'], 'user' => $userId));
         }
     }
     // redirect to the room, if we've ailed will be asked for guest's name again
     $this->redirectTo('/g/' . $code);
 }