Beispiel #1
0
// Fired after successfully adding a post with attachments and all required database
// and other changes.
//
//* $options hash - the same as in post.attach plus 'attachments' hash of File.
Event::listen(VANE_NS . 'post.added', function (array $options) {
    extract($options, EXTR_SKIP);
    $poster = $block->user(false);
    $to = User::all(arrize(\Vane\Current::config('general.post_notify_users')));
    if ($type === 'order' and $order = Order::find($object)) {
        foreach (array('user', 'manager') as $field) {
            $to[] = $order->{$field}()->first();
        }
    }
    foreach ($to as $recipient) {
        if (!$poster or $poster->email != $recipient->email) {
            \Vane\Mail::sendTo($recipient->emailRecipient(), 'vanemart::mail.order.post', array('order' => $order->to_array(), 'user' => $block->user()->to_array(), 'recipient' => $recipient->to_array(), 'post' => $post->to_array(), 'files' => func('to_array', $attachments)));
        }
    }
});
// Fired after post.added if post is attached to an object.
//
//* $object Eloquent
//* $options hash - the same as in post.added.
Event::listen(VANE_NS . 'post.object_ref', function (&$object, array $options) {
    $object->updated_at = new \DateTime();
});
/*-----------------------------------------------------------------------
| THUMB BLOCK
|----------------------------------------------------------------------*/
// Fired after creating and configuring ThumbGen instance for custom setup.
//
Beispiel #2
0
 function get_reset_password($email, $hash)
 {
     $days = \Vane\Current::config('general.password.reset_days');
     try {
         $email = $this->decodeValue($email);
         $user = User::where('email', '=', $email)->first();
         if (!$user) {
             throw new Error('User not found');
         }
         $valid = false;
         for ($day = 0; $day <= $days; $day++) {
             if ($user->resetHash($day, $hash)) {
                 $valid = true;
                 break;
             }
         }
         if (!$valid) {
             throw new Error('Hash is invalid');
         }
         $newPassword = User::generatePassword();
         $user->password = $newPassword;
         $user->save();
         \Vane\Mail::sendTo($user->emailRecipient(), 'vanemart::mail.user.new_password', array('email' => $email, 'password' => $newPassword));
         $this->status('new_password');
         Auth::login($user->id);
     } catch (\Exception $e) {
         Log::error_User('Error while resetting password: '******'vanemart::login'));
 }
Beispiel #3
0
 function ajax_post_show($id = null)
 {
     $valid = Validator::make($this->in(), array('status' => 'in:' . join(',', Order::statuses())));
     if ($valid->fails()) {
         return $valid;
     } elseif (!($order = Order::find($id))) {
         return;
     } elseif (!$this->editable($order)) {
         return false;
     }
     $fields = array('status', 'name', 'surname', 'phone', 'address', 'notes');
     $fields = userFields($fields, 'order');
     $order->fill_raw(S::trim(Input::only($fields)));
     if (!$order->dirty()) {
         return E_UNCHANGED;
     }
     $changes = $order->changeMessages();
     $msg = __('vanemart::order.set.post', join($changes, "\n"))->get();
     $post = with(new Post())->fill_raw(array('type' => 'order', 'object' => $order->id, 'author' => $this->user()->id, 'flags' => 'field-change ' . ($this->can('manager') ? 'manager' : ''), 'body' => $msg, 'html' => format('post', $msg), 'ip' => Request::ip()));
     \DB::transaction(function () use($order, $post) {
         if (!$post->save()) {
             throw new Error("Cannot save new system post for order {$order->id}.");
         } elseif (!$order->save()) {
             throw new Error("Cannot update fields of order {$order->id}.");
         }
     });
     if ($order->user != $this->user()->id) {
         $to = $order->user()->first();
         \Vane\Mail::sendTo($to->emailRecipient(), 'vanemart::mail.order.post', array('order' => $order->to_array(), 'user' => $this->user()->to_array(), 'recipient' => $to->to_array(), 'post' => $post->to_array(), 'files' => array()));
     }
     return $order;
 }