Example #1
0
 /**
  * request
  *
  * @return  bool
  *
  * @throws \Exception
  */
 protected function request()
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         $this->setRedirect($this->router->http('forgot'), Translator::translate('windwalker.user.no.email'));
         return false;
     }
     $view = $this->getView();
     $token = md5($this->app->get('secret') . uniqid() . CryptHelper::genRandomBytes());
     $link = $this->router->http('forgot', array('task' => 'confirm', 'token' => $token), Router::TYPE_FULL);
     $user = User::get(array('email' => $email));
     if ($user->notNull()) {
         $password = new Password();
         $user->reset_token = $password->create($token);
         $user->reset_last = DateTime::create('now', DateTime::TZ_LOCALE)->toSql(true);
         User::save($user);
     }
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $view->setLayout('email')->render();
     // Please send email here.
     // ----------------------------------------------------
     // ----------------------------------------------------
     $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), array('This is test message.', $body));
     return true;
 }
Example #2
0
 /**
  * postSave
  *
  * @param Data $data
  *
  * @return  void
  */
 protected function postSave(Data $data)
 {
     $this->post = $data;
     $this->topic = $topic = $this->model->getRecord('Topic');
     $topic->load($data->topic_id);
     $this->category = $this->model->getRecord('Category');
     $this->category->load($topic->category_id);
     if ($this->isNew) {
         if (!$data->primary) {
             $user = User::get();
             $date = DateTime::create();
             $topic->last_reply_user = $user->id;
             $topic->last_reply_post = $data->id;
             $topic->last_reply_date = $date->toSql();
             $topic->replies++;
             $topic->store();
         } else {
             $this->category->topics++;
         }
         $this->category->posts++;
         $this->category->store();
     }
     // Mail
     $this->sendMail($topic, $data);
     // Add Notification
     Notification::addNotification('topic', $topic->id, $topic->user_id);
 }
Example #3
0
 /**
  * prepareRecord
  *
  * @param Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     if (!$record->id) {
         $record->version = 1;
         $record->rating = 0;
         $record->state = 1;
         $record->user_id = $user->id;
         $record->created = $date->toSql();
         $record->created_by = $user->id;
         $this->setOrderPosition($record);
     } else {
         $record->modified = $date->toSql();
         $record->modified_by = $user->id;
     }
 }
Example #4
0
 /**
  * prepareRecord
  *
  * @param Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     // New
     if (!$record->id) {
         $record->user_id = $user->id;
         $record->created_by = $user->id;
         $record->version = 1;
         $record->replies = 1;
         $record->hits = 0;
         $record->favorites = 0;
         $record->rating = 0;
         $record->created = $date->toSql();
         $record->state = 1;
     }
     $record->last_reply_user = $user->id;
     $record->last_reply_date = $date->toSql();
 }
Example #5
0
 /**
  * prepareRecord
  *
  * @param NestedRecord|Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     if (!$record->alias) {
         $record->alias = $record->title;
     }
     $record->alias = OutputFilter::stringURLUnicodeSlug($record->alias);
     if (!$record->alias) {
         $record->alias = OutputFilter::stringURLSafe($date->format('Y-m-d-H-i-s'));
     }
     // Created date
     if (!$record->created) {
         $record->created = $date->toSql();
     }
     // Modified date
     if ($record->id) {
         $record->modified = $date->toSql();
     }
     // Created user
     if (!$record->created_by) {
         $record->created_by = $user->id;
     }
     // Modified user
     if ($record->id) {
         $record->modified_by = $user->id;
     }
     // Set Ordering or Nested ordering
     if (!$record->id) {
         $record->setLocation($record->parent_id, $record::LOCATION_LAST_CHILD);
     }
     if (!$record->id) {
         $record->state = 1;
         $record->access = 1;
         $record->topics = 0;
         $record->posts = 0;
     }
 }
Example #6
0
 /**
  * prepareDefaultData
  *
  * @param DataInterface|UserDataTrait $user
  *
  * @return  void
  */
 protected function prepareDefaultData(DataInterface $user)
 {
     $user->registered = $user->registered ?: DateTime::create()->format(DateTime::getSqlFormat());
     $user->blocked = $user->blocked === null ? 1 : $user->blocked;
 }
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return  bool
  *
  * @throws ValidateFailException
  * @throws \Exception
  */
 protected function doSave(DataInterface $data)
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $view = $this->getView();
     $user = User::get(array('email' => $email));
     if ($user->isNull()) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $token = UserHelper::getToken($user->email);
     $link = $this->router->route('forget_confirm', array('token' => $token, 'email' => $email), CoreRouter::TYPE_FULL);
     $password = new Password();
     $user->reset_token = $password->create($token);
     $user->last_reset = DateTime::create()->toSql();
     User::save($user);
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $this->getMailBody($view);
     $this->sendEmail($user->email, $body);
     return true;
 }
Example #8
0
 /**
  * Created date.
  *
  * @param string $format The date format.
  * @param bool   $local  Use local timezone.
  *
  * @return string Date string.
  */
 public function createdDate($format = '', $local = false)
 {
     $field = $this->config->get('field.created', 'created');
     $format = $format ?: DateTime::$format;
     if ($local) {
         return DateTime::toLocalTime($this->current->{$field}, $format);
     }
     return DateTime::create($this->current->{$field})->format($format);
 }
Example #9
0
 /**
  * getDate
  *
  * @param string $date
  * @param bool   $tz
  *
  * @return DateTime
  */
 public function getDate($date = 'now', $tz = DateTime::TZ_LOCALE)
 {
     return DateTime::create($date, $tz);
 }