Example #1
0
 static function createBy(User $user, array $info)
 {
     $fields = array('name', 'surname', 'address', 'phone', 'notes');
     $fields = userFields($fields, 'order');
     $order = with(new static())->fill_raw(array_intersect_key($info, array_flip($fields)))->fill_raw(array('password' => static::generatePassword(), 'user' => $user->id, 'manager' => \Vane\Current::config('general.new_order_manager'), 'sum' => Cart::subtotal(), 'ip' => Request::ip()));
     return Event::insertModel($order, 'order');
 }
Example #2
0
 function ajax_post_index()
 {
     $input = $this->in();
     $rules = array('email' => 'required|email', 'name' => 'required', 'surname' => 'required', 'address' => 'min:5', 'phone' => 'required|min:7|vanemart_phone');
     $rules += (array) \Vane\Current::config('general.user_fields.order');
     $valid = Validator::make($input, $rules);
     if ($this->can('checkout.deny')) {
         return false;
     } elseif (!Cart::has() or Cart::isTooSmall()) {
         return E_INPUT;
     } elseif ($valid->fails()) {
         return $valid;
     } else {
         \DB::transaction(function () use(&$input, &$user, &$order) {
             $user = User::findOrCreate($input);
             $order = Order::createBy(head(arrize($user)), $input);
             $goods = S(Cart::all(), function ($qty, $product) use($order) {
                 return compact('qty', 'product') + array('order' => $order->id);
             });
             OrderProduct::insert($goods);
         });
         $newUser = is_array($user);
         if ($newUser) {
             list($user, $password) = $user;
         }
         $options = compact('user', 'order') + array('block' => $this);
         if ($newUser) {
             $options += compact('password');
             $event = 'checkout.reg_user';
         } else {
             $event = 'checkout.old_user';
         }
         Event::fire($event, array($user, &$options));
         Event::fire('checkout.done', array($user, &$options));
         return $order;
     }
 }
Example #3
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'));
 }
Example #4
0
            $max = -1;
        } else {
            $max = \Config::get('vanemart::post.add.max_attaching_files', 10);
        }
        $attached = $options['post']->attach('attach', $max, $block->user());
        $models = array_merge($models, $attached);
    }
});
// 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.
Example #5
0
function userFields($fields, $namespace)
{
    return array_merge($fields, array_keys((array) \Vane\Current::config('general.user_fields.' . $namespace)));
}
Example #6
0
 function titleVars(array $vars, $action)
 {
     $name = $this->langVarName("{$action}.title");
     if (\Lang::has($name)) {
         $page = \Lang::line($name, $this->title)->get();
         $vars = compact('page') + \Vane\Current::config('company');
         return S::keep($vars, 'is_scalar');
     }
 }