Exemplo n.º 1
0
 public function seedImage(User $user)
 {
     $file = $this->faker->imageUrl(600, 400, 'people');
     Debugger::debug($file, 'image url');
     $image = new Image($file);
     Debugger::debug($image, 'image class');
     $filename = md5($file . $user->get('id')) . '.jpg';
     $imageDir = 'assets/images/profile-pics/original/';
     $imageDir .= substr($filename, 0, 1) . '/';
     $imageDir .= substr($filename, 1, 1) . '/';
     $imageDir .= substr($filename, 2, 1) . '/';
     if (!is_dir(PUBLIC_ROOT . $imageDir)) {
         mkdir(PUBLIC_ROOT . $imageDir, 0777, true);
     }
     $saveName = PUBLIC_ROOT . $imageDir . $filename;
     Debugger::debug($saveName, 'save name');
     $image->save($imageDir . $filename);
     $thumbnail = $this->seedThumbnail($image, $imageDir, $user);
     // update the database
     $userImage = new UserImage();
     $userImage->set('user_id', $user->get('id'));
     $userImage->set('image_url', '/' . $imageDir . $filename);
     $userImage->set('thumbnail', '/' . $thumbnail);
     $userImage->set('main_image', 1);
     $userImage->save();
 }
Exemplo n.º 2
0
 public function signin()
 {
     $userModel = new \Models\User();
     $helper = $this->fb->getRedirectLoginHelper();
     $permissions = ['email', 'user_likes'];
     // optional
     $callback_url = DIR . 'account/fblogin';
     $this->data['loginUrl'] = $helper->getLoginUrl($callback_url, $permissions);
     if (isset($_POST['email']) && !empty($_POST['email'])) {
         $login = $userModel->login($_POST['email'], md5($_POST['password']));
         if (!is_bool($login)) {
             Session::set('user_id', $login->user_id);
             Session::set('user', $login);
             //redirects user to last visited page
             $redirectUrl = Session::get('redirectLogin');
             Session::destroy('redirectLogin');
             if (isset($redirectUrl) && $redirectUrl != '') {
                 Url::redirect($redirectUrl);
             } else {
                 Url::redirect('board');
             }
         } else {
             Session::set('error', 'Login Fails!');
         }
     }
     $this->data['title'] = 'Sign In';
     View::rendertemplate('header', $this->data);
     View::render('account/signin', $this->data);
     View::rendertemplate('footer', $this->data);
 }
Exemplo n.º 3
0
 public function actionEdit_status()
 {
     $user = new User();
     $user->find()->where(['id' => $_POST['userID']])->one();
     $user->status = $_POST['status'];
     $user->save();
 }
Exemplo n.º 4
0
 public function index()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     $db = $f3->get('db.instance');
     $tickets = $db->exec('SELECT * FROM support_tickets WHERE memberId = ? ORDER BY id DESC', $user['id']);
     foreach ($tickets as $id => $ticket) {
         $result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
         $tickets[$id]['messages_count'] = $result[0]['count'];
         // Assigned or not ?
         if ($ticket['assignedUserId'] != 0) {
             $assignedUser = new User();
             $assignedUser->load($ticket['assignedUserId']);
             $tickets[$id]['assignedUser'] = $assignedUser->cast();
         }
     }
     $f3->set('tickets', $tickets);
     $active_tickets = $db->exec("SELECT * FROM support_tickets WHERE memberId = ? AND status != 'closed'", $user['id']);
     $f3->set('active_tickets', $active_tickets);
     $closed_tickets = $db->exec("SELECT * FROM support_tickets WHERE memberId = ? AND status = 'closed'", $user['id']);
     $f3->set('closed_tickets', $closed_tickets);
     $f3->set('target', 'support/index.html');
     $this->_render('base.html');
 }
Exemplo n.º 5
0
 public function index()
 {
     $userModel = new User();
     $userModel->all();
     $users = $userModel->all();
     return view('index', compact('users'));
 }
Exemplo n.º 6
0
 public function index()
 {
     $data['title'] = $this->language->get('title');
     $user = new User();
     var_dump($user->getData());
     View::renderTemplate('header', $data);
     View::render('welcome/welcome', $data);
     View::renderTemplate('footer', $data);
 }
Exemplo n.º 7
0
Arquivo: Auth.php Projeto: fant0m/VAII
 public static function register($email, $nick, $password)
 {
     $user = new User();
     $user->email = $email;
     $user->nick = $nick;
     $user->password = password_hash($password, PASSWORD_DEFAULT);
     $user->save();
     return $_SESSION['user'] = $user->id;
 }
 public function banUser($id)
 {
     if ($this->user->banUser($id) !== 1) {
         Session::setError('something went wrong');
         Redirect::back();
     }
     Session::setMessage('Done');
     Redirect::to('/admin/users');
 }
Exemplo n.º 9
0
 public function seedEmail(User $user)
 {
     Debugger::debug('Seeding email');
     $userEmail = new Email();
     $userEmail->set('user_id', $user->get('id'));
     $userEmail->set('email', $this->faker->freeEmail);
     $userEmail->set('primary', 1);
     $userEmail->save();
 }
Exemplo n.º 10
0
 public function actionReg()
 {
     $vk_id = $this->app->cookie->get('vk_id');
     $user = new User();
     $user->find()->where(['vk_id' => $vk_id])->one();
     $user->status = $_GET['status'] == 1 ? 2 : 1;
     $user->save();
     $this->app->parser->render('profile', ['user' => $user]);
 }
Exemplo n.º 11
0
 protected function create()
 {
     $params = arrayKeysSnakeToCamel($_POST['user']);
     $user = new User();
     $user->fromArray($params);
     $user->save();
     $this->addFlash("success", "registered");
     redirectTo("/");
 }
Exemplo n.º 12
0
 public function start()
 {
     if ($this->user) {
         return $this->app->parser->renderW('main_menu', ['user' => $this->user], false);
     } else {
         $user = new User();
         $user->find()->where(['vk_id' => Cookie::get('vk_id')])->one();
         return $this->app->parser->renderW('main_menu', ['user' => $user], false);
     }
 }
Exemplo n.º 13
0
 public function connect(Application $app)
 {
     // creates a new controller based on the default route
     $front = $app['controllers_factory'];
     $front->get("/", 'FrontController\\Homepage::index')->bind("homepage");
     $front->match("/final_test", 'FrontController\\FinalTest::index')->bind("final_test");
     $front->match("/control_test", 'FrontController\\ControlTest::index')->bind("control_test");
     $front->match("/{course_type}", 'FrontController\\CourseType::index')->bind("course_type");
     //$front->post("/{course_type}", 'FrontController\Score::index')->bind("course_type");
     $app->get('/logout', function (Request $request) use($app) {
         $app['session']->set('username', '');
         $app['session']->set('id', '');
         $redirect = $app["url_generator"]->generate("homepage");
         return $app->redirect($redirect);
     })->bind("logout");
     $app->post('/login-check', function (Request $request) use($app) {
         $em = $app['orm.em'];
         $qb = $em->createQueryBuilder();
         if (null !== $request->get('username2')) {
             $username = $request->get('username2');
             $query = $qb->select('u')->from('models\\User', 'u')->where("u.username = '******'")->getQuery();
             $result = $query->getResult();
             $result_count = count($result);
             if ($result_count > 0) {
                 return 'Helaas, de gebruikersnaam die je hebt ingevoerd bestaat al, probeer eens een andere.';
             } else {
                 $user = new User();
                 $user->setUsername($username);
                 $user->setRoles("ROLE_USER");
                 $em->persist($user);
                 $em->flush();
                 $id = $user->getId();
                 $app['session']->set('id', $id);
                 $app['session']->set('username', $username);
                 return 'succes';
             }
         } else {
             if ($request->get('username') != '') {
                 $username = $request->get('username');
                 $query = $qb->select('u')->from('models\\User', 'u')->where("u.username = '******'")->getQuery();
                 $result = $query->getResult();
                 $result_count = count($result);
                 if ($result_count < 1) {
                     return 'De gebruikersnaam die je hebt ingevoerd bestaat niet, probeer het eens opnieuw.';
                 } else {
                     $id = $result[0]->id;
                     $app['session']->set('id', $id);
                     $app['session']->set('username', $username);
                     return 'succes';
                 }
             }
         }
     })->bind("login_check");
     return $front;
 }
Exemplo n.º 14
0
 function users()
 {
     if (Session::isSession('user')) {
         $user = new User();
         $usersData = $user->getAll();
         $this->view->addUsers($usersData);
         $this->view->forAjax('users');
     } else {
         Error::authFail();
     }
 }
Exemplo n.º 15
0
 public function actionMy()
 {
     $vk_id = Cookie::get('vk_id');
     $user = new User();
     $user->find()->where(['vk_id' => $vk_id])->one();
     $user->status = $_GET['status'] == 1 ? 2 : 1;
     $user->save();
     $region = new GeobaseRegion();
     $city = new GeobaseCity();
     $regionAll = $region->find()->orderBy('name', 'ASC')->all();
     $this->app->parser->render('profile', ['user' => $user, 'regionAll' => $regionAll]);
 }
Exemplo n.º 16
0
 function registerUser($postdata)
 {
     $regname = htmlentities($postdata['regname']);
     $regpass = htmlentities($postdata['regpass']);
     $regauth = htmlentities($postdata['regauth']);
     $regpass = hash('sha256', $regpass);
     $user = new User();
     $user->setName($regname);
     $user->setPassword($regpass);
     $user->setAuthlevel($regauth);
     $user->save();
 }
Exemplo n.º 17
0
 public function __construct()
 {
     parent::__construct();
     $id = Register::get('id');
     if (!empty($id)) {
         $user = new User($id);
         $user->setLastVisit();
         $user->writeData(true);
         $this->logout();
     }
     $this->logout();
 }
Exemplo n.º 18
0
 /**
  * Processing of change user password form
  *
  * @param \Nette\Application\UI\Form $form
  *
  * @Privilege("default")
  */
 public function changePasswordSucceded(\Nette\Application\UI\Form $form)
 {
     $values = $form->getValues(TRUE);
     $row = $this->users->get($this->user->id);
     if (!\Nette\Security\Passwords::verify($values['oldpassword'], $row->password)) {
         $form->addError('Nesprávné heslo.');
     } else {
         $this->users->updatePassword($row->id, $values['password']);
         $this->flashMessage('Heslo bylo změněno');
     }
     $this->redirect('this');
 }
Exemplo n.º 19
0
 public function index()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $this->_requireRank('support');
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     $db = $f3->get('db.instance');
     $tickets = $db->exec('SELECT * FROM support_tickets ORDER BY id DESC');
     foreach ($tickets as $id => $ticket) {
         $result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
         $tickets[$id]['messages_count'] = $result[0]['count'];
         // Assigned or not ?
         if ($ticket['assignedUserId'] != 0) {
             $assignedUser = new User();
             $assignedUser->load($ticket['assignedUserId']);
             $tickets[$id]['assignedUser'] = $assignedUser->cast();
         }
         // From who ?
         $ticketCreator = new User();
         $ticketCreator->load($ticket['memberId']);
         $tickets[$id]['member'] = $ticketCreator->cast();
     }
     $f3->set('tickets', $tickets);
     $active_tickets = $db->exec("SELECT * FROM support_tickets WHERE status != 'closed'");
     $f3->set('active_tickets', $active_tickets);
     $closed_tickets = $db->exec("SELECT * FROM support_tickets WHERE status = 'closed'");
     $f3->set('closed_tickets', $closed_tickets);
     // Very high priority tickets
     $prio_tickets = $db->exec("SELECT * FROM support_tickets WHERE status != 'closed' AND priority = 4 ORDER BY id DESC");
     foreach ($prio_tickets as $id => $ticket) {
         $result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
         $prio_tickets[$id]['messages_count'] = $result[0]['count'];
         // Assigned or not ?
         if ($ticket['assignedUserId'] != 0) {
             $assignedUser = new User();
             $assignedUser->load($ticket['assignedUserId']);
             $prio_tickets[$id]['assignedUser'] = $assignedUser->cast();
         }
         // From who ?
         $ticketCreator = new User();
         $ticketCreator->load($ticket['memberId']);
         $prio_tickets[$id]['member'] = $ticketCreator->cast();
     }
     $f3->set('priority_tickets', $prio_tickets);
     // Some side-bar stats
     $result = $db->exec('SELECT count(*) AS `count` FROM users');
     $f3->set('users_count', $result[0]['count']);
     $f3->set('tickets_count', count($active_tickets));
     $f3->set('target', 'dashboard/admin/support/index.html');
     $this->_render('base.html');
 }
Exemplo n.º 20
0
 /**
  * @BingingModel RegisterUserBingingModel
  */
 public function postregister(RegisterUserBingingModel $userBindingModel)
 {
     if ($userBindingModel) {
         $user = new User();
         $user->setUsername($userBindingModel->getUsername());
         $user->setPassword($userBindingModel->getPassword());
         $user->setCash(10000);
         $this->data->register($user);
     }
     $this->view->appendToLayout('main', 'register');
     $this->view->display('layouts.default');
 }
Exemplo n.º 21
0
 public function logintry($postdata)
 {
     $inputname = $postdata['inputname'];
     $inputpass = $postdata['inputpass'];
     $user = new User();
     $user->findByName($inputname);
     if ($user->getPassword() === hash('sha256', $inputpass)) {
         Session::create('user', $user->getName());
     } else {
         echo 0;
     }
 }
Exemplo n.º 22
0
 public function actionLogin()
 {
     if (!App::instance()->isGuest()) {
         $this->redirect('/site/index/');
     }
     $user = new User();
     if (isset($_POST['User']) && $user->load($_POST['User']) && $user->login()) {
         $_SESSION['loggedUserId'] = App::instance()->user->id;
         $this->redirect('/site/index/');
     }
     $this->render('login', ['user' => $user]);
 }
Exemplo n.º 23
0
 public function detailspost()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $this->_requireRank('support');
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     $db = $f3->get('db.instance');
     // Target user
     $tuser_id = $f3->get('PARAMS.id');
     $tuser = new User();
     $tuser->load($tuser_id);
     if ($tuser->rank > $user['rank']) {
         $f3->reroute($f3->get('PATH'));
     }
     // Update one by one
     $name = $f3->get('POST.tname');
     $username = $f3->get('POST.tusername');
     $email = $f3->get('POST.temail');
     $age = (int) $f3->get('POST.tage');
     $rank = $f3->get('POST.trank');
     $errors = [];
     if (empty($name)) {
         $errors[] = "Name is required";
     }
     if (!preg_match("/^[0-9a-z]{4,}\$/i", $username)) {
         $errors[] = "Usernames must be at least 4 characters and can only contain letters and numbers.";
     }
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $errors[] = "A valid email address is required.";
     }
     // Prevent setting the users rank to a rank higher then the user's one
     if ($rank > $user['rank']) {
         $errors[] = 'You can not set the users rank to a rank higher then yours';
     }
     if (empty($errors)) {
         $tuser->name = $name;
         $tuser->username = $username;
         $tuser->email = $email;
         $tuser->age = $age;
         $tuser->rank = $rank;
         $tuser->save();
         new Notification('Updated users profile successfully !', 'success', true);
         $f3->reroute($f3->get('PATH'));
     } else {
         $f3->set('errors', $errors);
         $f3->set('tuser', $tuser->cast());
         $f3->set('target', 'dashboard/admin/users/details.html');
         $this->_render('base.html');
     }
 }
Exemplo n.º 24
0
 public function actionReg()
 {
     $vk_id = Cookie::get('vk_id');
     $user = new User();
     $user->find()->where(['vk_id' => $vk_id])->one();
     $user->status = $_GET['status'] == 1 ? 2 : 1;
     $user->save();
     Header::redirect('/vk2/profile/my', true, 302);
     /*$this->app->parser->render('profile',
       [
           'user' =>$user,
       ]);*/
 }
 public function registerAction()
 {
     $user = new User();
     $success = $user->save($this->request->getPost());
     if ($success) {
         return $this->redirect('signin/index');
     } else {
         echo 'Sorry, the following problems were generated: ';
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), '<br/>';
         }
     }
     $this->view->disable();
 }
Exemplo n.º 26
0
 public function ajaxSignIn()
 {
     extract($_POST['input']);
     if (isset($remember)) {
         \Models\Auth::remember($username, $password);
     }
     $user = Models\User::signIn($username, sha1($password));
     if (!isset($user['id'])) {
         $data['name'] = 'password';
         $data['notice'] = 'Invalid login or password. Please try again.';
         echo json_encode($data, JSON_UNESCAPED_UNICODE);
         die;
     }
     $activated_at = \Models\User::getUserActivatedAt($username, sha1($password));
     if (!isset($activated_at['activated_at']) || $activated_at['activated_at'] == null) {
         $data['name'] = 'password';
         $data['notice'] = 'Your account is not activated. Please, activate it at first.';
         echo json_encode($data, JSON_UNESCAPED_UNICODE);
         die;
     } else {
         \Models\Auth::userInSession($user);
         $data['notice'] = true;
         $data['id'] = $user['id'];
         echo json_encode($data, JSON_UNESCAPED_UNICODE);
         die;
     }
 }
 public function sellProduct($id, $quantity, $upid)
 {
     $this->user->startTran();
     if ($this->user->changeProductQuantity(Auth::getUserId(), $id, $quantity, $upid) !== 1) {
         Session::setError('not enough products');
         $this->user->rollback();
         Redirect::back();
     }
     $userProduct = $this->user->getProduct(Auth::getUserId(), $id, $upid);
     if ($userProduct['quantity'] < 1) {
         if ($this->user->deleteProduct(Auth::getUserId(), $id, $upid) !== 1) {
             Session::setError('something went wrong');
             $this->user->rollback();
             Redirect::back();
         }
     }
     $soldProducts = $this->product->getProduct($id);
     if ($this->product->addQuantity($soldProducts['id'], $quantity) !== 1) {
         Session::setError('something went wrong');
         $this->user->rollback();
         Redirect::back();
     }
     if ($this->user->addCash(Auth::getUserId(), $soldProducts['price'] * $quantity) !== 1) {
         Session::setError('something went wrong');
         $this->user->rollback();
         Redirect::back();
     }
     $this->user->commit();
     Session::setMessage('You sold ' . $quantity . ' of ' . $userProduct['name']);
     Redirect::to('/user/' . Auth::getUserId() . '/products');
 }
Exemplo n.º 28
0
 public function index()
 {
     if (!isset($_GET['code'])) {
         header("Location: ../sign-in/index");
         exit;
     }
     $testActivation = \Models\User::getUsernameByActivationCode($_GET['code']);
     if (!isset($testActivation['username'])) {
         echo \Core\View::make('header', ['title' => 'Activation unsuccessful']);
         echo \Core\View::make('activation.bad');
         echo \Core\View::make('footer');
     } else {
         $date = date('Y-m-d H:i:s');
         $user = \Models\User::setUserActivatedAt($date, $_GET['code']);
         if (isset($user['id'])) {
             $subject = 'Welcome';
             $body = "Congratulations. Your account is activated.";
             $result = Mailer::send($user['email'], $subject, $body);
             if ($result == 'Message has been sent') {
                 echo \Core\View::make('header');
                 echo \Core\View::make('activation.good', ['title' => 'Activation successful']);
                 echo \Core\View::make('footer');
             }
         }
     }
 }
Exemplo n.º 29
0
 function deletePost($alias)
 {
     if (Session::isSession('user')) {
         $user = new User();
         $user->findByName(Session::getData('user'));
         $authlevel = $user->getAuthlevel();
         if ($authlevel > 3) {
             $toDelete = new PostModel();
             $toDelete->deleteByAlias($alias);
             $posts = new PostModel();
             $this->view->addAuthlevel($authlevel);
             $this->view->addPosts($posts->getAll());
             $this->view->forAjax('index');
         }
     }
 }
Exemplo n.º 30
0
 /**
  * Override the get_avatar by default from WP
  */
 protected static function getAvatar()
 {
     /*
      * We will get the avatar from our models
      */
     add_filter('get_avatar', function ($avatar = '', $id_or_email, $size = User::AVATAR_SIZE_DEFAULT, $default = '', $alt = '') {
         if (is_numeric($id_or_email)) {
             $user_id = (int) $id_or_email;
         } elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) {
             $user_id = $user->ID;
         } elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) {
             $user_id = (int) $id_or_email->user_id;
         }
         $user = User::find($user_id);
         if (!$user) {
             return Utils::getUrlAvatarDefault($size);
         }
         if (!Utils::isValidStr($alt)) {
             $alt = $user->getDisplayName() . ' avatar';
         }
         $img = '<img alt="' . esc_attr($alt) . '" src="' . $user->getAvatar($size) . '" ';
         $img .= 'class="avatar photo" height="' . $size . '" width="' . $size . '">';
         return $img;
     }, 10, 5);
 }