Exemple #1
0
 public static function create($data)
 {
     $user = ORM::factory('User');
     $user->create_user($data, array('username', 'password', 'email'));
     $user->add_role('login');
     $mail = mail::create('usercreated')->to($user->email)->tokenize(array('username' => $user->username))->send();
     user::login(arr::get($data, 'email', ''), arr::get($data, 'password', ''));
 }
    protected function _execute(array $params)
    {
        $query = DB::query(Database::SELECT, 'SELECT
			user.id,
			user.email,
			opt.reminder,
			opt.last_reminder,
			opt.next_reminder
		FROM
			`users` AS user
		JOIN
			`user_options` AS opt
			ON
				user.id = opt.user_id
		WHERE
			opt.reminder = 1
		AND
			opt.next_reminder > ' . strtotime('-5 minutes') . '
		AND
			opt.next_reminder < ' . strtotime('+5 minutes') . '
		AND
			user.email != "";');
        $results = $query->execute()->as_array();
        if (is_array($results)) {
            $sent = array();
            foreach ($results as $result) {
                $user = ORM::factory('User', arr::get($result, 'id', ''));
                if ($user->loaded()) {
                    if (!in_array($user->email, $sent)) {
                        $sent[] = $user->email;
                        // Send the mail here..
                        $mail = mail::create('reminder')->to($user->email)->tokenize(array('username' => $user->username, 'writeurl' => 'http://morningpages.net/write', 'link' => HTML::anchor('http://morningpages.net/write', 'It’s time to write your Morning Pages'), 'contactlink' => HTML::anchor('http://morningpages.net/contact', 'contact us')))->send();
                        // Then:
                        $option = $user->option;
                        $option->last_reminder = time();
                        $option->next_reminder = $user->get_next_reminder(true);
                        //$option->save();
                    }
                }
            }
        }
    }
Exemple #3
0
 public function action_contact()
 {
     $errors = false;
     if ($_POST) {
         $val = Validation::factory($_POST);
         $val->rule('sprot', 'exact_length', array(':value', 1));
         $val->rule('email', 'not_empty');
         $val->rule('email', 'email');
         $val->rule('suggestion', 'not_empty');
         if ($val->check()) {
             notes::success('Your message has been sent and we will get back to you as soon as possible. Thanks!');
             $mail = mail::create('suggestion')->to('*****@*****.**')->from(arr::get($_POST, 'email', ''))->content(arr::get($_POST, 'suggestion') . '<br /><br />.E-mail: ' . arr::get($_POST, 'email', ''))->subject('Message to ' . site::option('sitename'))->send();
             site::redirect('contact');
         } else {
             $errors = $val->errors('suggestions');
         }
     }
     $this->bind('errors', $errors);
     seo::instance()->title("Contact Morning Pages");
     seo::instance()->description("Feel free to contact MorningPages.net if you have questions or concerns about your account, the site or for more information regarding your Morning Pages.");
 }
Exemple #4
0
 public function action_talk()
 {
     $tag = $this->request->param('tag');
     $talk = $this->request->param('talk');
     if (user::logged()) {
         // Iterate views
         if ($talk->user_id != user::get()->id) {
             $talk->views = $talk->views + 1;
             try {
                 $talk->save();
             } catch (ORM_Validation_Exception $e) {
                 //var_dump($e->errors());
             }
         }
         // Set when the user last saw the topic
         $user = user::get();
         $viewed = $user->talkviews->where('talk_id', '=', $talk->id)->find();
         if (!$viewed->loaded()) {
             $viewed->user_id = $user->id;
             $viewed->talk_id = $talk->id;
         }
         $viewed->last = time();
         $viewed->save();
     }
     $replies = $talk->replies->where('op', '!=', 1);
     $counter = $talk->replies->where('op', '!=', 1);
     $limit = Kohana::$config->load('talk')->get('pagination_limit');
     $numreplies = $counter->count_all();
     $numpages = ceil($numreplies / $limit);
     $page = (int) arr::get($_GET, 'page', 0);
     if ($_POST) {
         $this->require_login();
         $reply = ORM::factory('Talkreply');
         $reply->values($_POST);
         $reply->user_id = user::get()->id;
         $reply->talk_id = $talk->id;
         try {
             $reply->save();
             $page = $numpages;
             $talk->last_reply = time();
             $talk->save();
             $subscriptions = $talk->subscriptions->find_all();
             if ((bool) $subscriptions->count()) {
                 foreach ($subscriptions as $subscription) {
                     if ($subscription->user_id != $reply->user_id) {
                         mail::create('talkreplyposted')->to($subscription->user->email)->tokenize(array('username' => $subscription->user->username, 'sendername' => $reply->user->username, 'title' => $talk->title, 'reply' => $reply->content, 'link' => HTML::anchor(URL::site($talk->url() . '?page=' . $page . '#comment-' . $reply->id, 'http'), $talk->title)))->send();
                     }
                 }
             }
             $vote = ORM::factory('User_Talkvote');
             $vote->type = 'talkreply';
             $vote->user_id = user::get()->id;
             $vote->object_id = $reply->id;
             $vote->save();
             notes::success('Your reply has been posted.');
             site::redirect($talk->url() . '?page=' . $page . '#comment-' . $reply->id);
         } catch (ORM_Validation_Exception $e) {
             notes::error('Whoops! Your submission contained errors. Please review it and submit again');
             $errors = $e->errors();
         }
     }
     if ($page < 1) {
         $page = 1;
     }
     if ($page > $numpages) {
         $page = $numpages;
     }
     $replies = $replies->limit($limit);
     if ($page - 1 > 0) {
         $replies = $replies->offset($limit * ($page - 1));
     }
     $replies = $replies->find_all();
     $this->bind('tag', $tag);
     $this->bind('talk', $talk);
     $this->bind('replies', $replies);
     $this->bind('tags', ORM::factory('Talktag')->find_all());
     $this->bind('numpages', $numpages);
     $this->bind('currentpage', $page);
     seo::instance()->title($talk->title);
     seo::instance()->description("Talk About Morning Pages, or anything else you might find interesting. Use this area to ask questions, make friends, or find out information about Morning Pages.");
 }
Exemple #5
0
 public function send_password_email($password)
 {
     try {
         $mail = mail::create('userautocreated')->to($this->email)->tokenise(array('username' => $this->username, 'password' => $password))->send();
         return true;
     } catch (exception $e) {
         log::instance('Couldnt send user autogenerated password', $e);
     }
     return false;
 }
Exemple #6
0
 public function action_help()
 {
     if ($_POST) {
         $user = ORM::factory('User')->where('email', '=', $_POST['email'])->find();
         if ($user->loaded()) {
             $token = ORM::factory('User_Token');
             $token->user_id = $user->id;
             $token->created = time();
             $token->expires = strtotime('+2 hours');
             //$token -> type = 'password';
             $token->save();
             $mail = mail::create('userforgotpass')->to($user->email)->tokenize(array('username' => $user->username, 'resetlink' => user::url('password/' . $token->token, 'http')))->send();
             notes::info('Check your e-mail! We\'ve sent you a mail with instructions on resetting your password.');
             user::redirect('login');
         } else {
             $url = user::url('signup');
             notes::add('error', 'No account is registerred with that e-mail address');
         }
     }
 }