示例#1
0
 /**
  * @return string
  */
 public function authorAvatar()
 {
     if ($this->user) {
         return $this->user->present()->avatar;
     }
     return Gravatar::image($this->author_email, 300, 'identicon');
 }
示例#2
0
 public function action_user($id = null)
 {
     if (intval($id) < 1) {
         throw new NotFoundHttpException();
     }
     $data = [];
     $form = [];
     try {
         /** @var \Foolz\FoolFrame\Model\Users $users */
         $users = $this->getContext()->getService('users');
         $data['object'] = $users->getUserBy('id', $id);
         $data['object']->password = '';
     } catch (\Foolz\FoolFrame\Model\UsersWrongIdException $e) {
         throw new NotFoundHttpException();
     }
     $form['open'] = array('type' => 'open');
     $form['paragraph'] = array('type' => 'paragraph', 'help' => _i('You can customize your account here.'));
     $form['paragraph-2'] = array('type' => 'paragraph', 'help' => '<img src="' . Gravatar::image($data['object']->email) . '" width="80" height="80" style="padding:2px; border: 1px solid #ccc;"/> ' . _i('The avatar is automatically fetched from %s, based on the user\'s registration email.', '<a href="http://gravatar.com" target="_blank">Gravatar</a>'));
     if ($this->getAuth()->hasAccess('users.change_credentials')) {
         $form['username'] = array('type' => 'input', 'database' => true, 'label' => _i('Username'), 'class' => 'span3', 'help' => _i('Change the username'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]);
         $form['email'] = array('type' => 'input', 'database' => true, 'label' => _i('Email'), 'class' => 'span3', 'help' => _i('Change the email'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]);
         $form['password'] = array('type' => 'password', 'database' => true, 'label' => _i('Password'), 'class' => 'span3', 'help' => _i('Change the password (leave empty to not change it)'));
     }
     $form['bio'] = array('type' => 'textarea', 'database' => true, 'label' => 'Bio', 'style' => 'height:150px;', 'class' => 'span5', 'help' => _i('Some details about you'), 'validation' => [new Trim(), new Assert\Length(['max' => 360])]);
     $form['twitter'] = array('type' => 'input', 'database' => true, 'label' => 'Twitter', 'class' => 'span3', 'help' => _i('Your twitter nickname'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]);
     $form['display_name'] = array('type' => 'input', 'database' => true, 'label' => 'Display name', 'class' => 'span3', 'help' => _i('Alternative name in place of login username'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]);
     if ($this->getAuth()->hasAccess('users.change_group')) {
         $groups = $this->config->get('foolz/foolframe', 'foolauth', 'groups');
         $group_ids = [];
         foreach ($groups as $level => $group) {
             $group_ids[$level] = $group['name'];
         }
         $form['group_id'] = array('type' => 'radio', 'database' => true, 'label' => 'Display name', 'help' => _i('Change the group of the user'), 'radio_values' => $group_ids);
     }
     $form['submit'] = array('type' => 'submit', 'class' => 'btn btn-primary', 'value' => _i('Submit'));
     $form['close'] = array('type' => 'close');
     $data['form'] = $form;
     if ($this->getPost() && !$this->checkCsrfToken()) {
         $this->notices->set('warning', _i('The security token wasn\'t found. Try resubmitting.'));
     } elseif ($this->getPost()) {
         $result = Validator::formValidate($form, $this->getPost());
         if (isset($result['error'])) {
             $this->notices->set('warning', $result['error']);
         } else {
             if (isset($result['warning'])) {
                 $this->notices->set('warning', $result['warning']);
             }
             $this->notices->set('success', _i('Preferences updated.'));
             $user = $users->getUserBy('id', $id);
             $user->save($result['success']);
             $data['object'] = $user;
             $data['object']->password = '';
         }
     }
     // create a form
     $this->param_manager->setParam('method_title', [_i('Manage'), _i('Edit'), $data['object']->username]);
     $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data);
     return new Response($this->builder->build());
 }
示例#3
0
 /**
  * @return string
  */
 public function avatar()
 {
     $avatar = $this->entity->getAttribute('avatar');
     if (starts_with($avatar, 'http')) {
         return $avatar;
     }
     if (empty($avatar)) {
         return Gravatar::image($this->email, 300, 'identicon');
     }
     return url('uploads/avatars', [$avatar]);
 }
 /**
  * @param TextPreprocessor
  * @param string
  * @param string
  */
 public function __construct(TextPreprocessor $preprocessor, $gravatarMaxRating, $wwwDir)
 {
     $this->helpers['description'] = array($preprocessor, 'processDescription');
     $this->helpers['licenses'] = array($preprocessor, 'processLicenses');
     $this->helpers['gravatar'] = function ($email, $size = 40) use($gravatarMaxRating) {
         return html_entity_decode(Gravatar::image($email, $size, null, $gravatarMaxRating));
     };
     $this->helpers['profile'] = function ($id) {
         return 'https://forum.nette.org/en/profile.php?id=' . $id;
     };
     $this->helpers['mtime'] = function ($path) use($wwwDir) {
         return filemtime($wwwDir . DIRECTORY_SEPARATOR . $path);
     };
 }
示例#5
0
 function prepareForm($me)
 {
     $avatarform = $this->tpl();
     $p = new Picture();
     $p->get($this->user->getLogin());
     $avatarform->assign('photobin', $p->toBase());
     $avatarform->assign('me', $me);
     if (isset($me->email)) {
         $result = requestURL(Gravatar::profile($me->email, 'json'), 3);
         $obj = json_decode($result);
         if ($obj != 'User not found') {
             $avatarform->assign('gravatar_bin', base64_encode(requestURL('http://www.gravatar.com/avatar/' . $obj->entry[0]->hash . '?s=250')));
             $avatarform->assign('gravatar', $obj);
         }
     }
     $avatarform->assign('submit', $this->call('ajaxSubmit', "movim_form_to_json('avatarform')"));
     return $avatarform->draw('_avatar_form', true);
 }
示例#6
0
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return string
  */
 public function create(ServerRequestInterface $request, ResponseInterface $response)
 {
     $response->withHeader('Content-type', 'application/json');
     try {
         $data = $request->getParsedBody();
         $date = new \DateTime(date('Y-m-d H:i:s'));
         $entityManager = $this->getEntityManager();
         $user = new User();
         $user->setEmail($data['email'])->setName($data['name'])->setAvatar(Gravatar::image($data['email'], 120, 'mm'))->setPassword(md5($data['password']))->setLastUpdate($date)->setTimestamp($date);
         $entityManager->persist($user);
         $entityManager->flush();
         $token = $this->generateToken($user);
         return $response->getBody()->write(json_encode(['token' => $token]));
     } catch (DBAL\DBALException $e) {
         /**
          * TODO: describe all possible exceptions
          */
         return $response->withStatus(500);
     }
 }
示例#7
0
 public function action_profile()
 {
     if (!$this->getAuth()->hasAccess('maccess.user')) {
         return $this->redirectToLogin();
     }
     $data = [];
     $form = [];
     $form['open'] = array('type' => 'open');
     $form['paragraph'] = array('type' => 'paragraph', 'help' => _i('You can customize your account here.'));
     $form['paragraph-2'] = array('type' => 'paragraph', 'help' => '<img src="' . Gravatar::image($this->getAuth()->getUser()->getEmail()) . '" width="80" height="80" style="padding:2px; border: 1px solid #ccc;"/> ' . _i('Your avatar is automatically fetched from %s, based on your registration email.', '<a href="http://gravatar.com" target="_blank">Gravatar</a>'));
     $form['display_name'] = array('type' => 'input', 'database' => true, 'label' => _i('Display Name'), 'class' => 'span3', 'help' => _i('Alternative name in place of login username'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]);
     $form['bio'] = array('type' => 'textarea', 'database' => true, 'label' => 'Bio', 'style' => 'height:150px;', 'class' => 'span5', 'help' => _i('Some details about you'), 'validation' => [new Trim(), new Assert\Length(['max' => 360])]);
     $form['twitter'] = array('type' => 'input', 'database' => true, 'label' => 'Twitter', 'class' => 'span3', 'help' => _i('Your twitter nickname'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]);
     $form['submit'] = array('type' => 'submit', 'class' => 'btn btn-primary', 'value' => _i('Submit'));
     $form['close'] = array('type' => 'close');
     $data['form'] = $form;
     if ($this->getPost() && !$this->security->checkCsrfToken($this->getRequest())) {
         $this->notices->set('warning', _i('The security token wasn\'t found. Try resubmitting.'));
     } elseif ($this->getPost()) {
         $result = Validator::formValidate($form, $this->getPost());
         if (isset($result['error'])) {
             $this->notices->set('warning', $result['error']);
         } else {
             if (isset($result['warning'])) {
                 $this->notices->set('warning', $result['warning']);
             }
             $this->notices->set('success', _i('Your profile has been updated.'));
             $user = $this->getAuth()->getUser();
             $user->save($result['success']);
         }
     }
     $data['object'] = (object) $this->getAuth()->getUser();
     // generate profile form
     $this->param_manager->setParam('method_title', _i('Profile'));
     $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data);
     return new Response($this->builder->build());
 }