/**
  * second sequence 
  * Method untuk menyimpan data tenant dan menampilkan form tenant
  */
 public function actionCreate()
 {
     $model = new Tenant();
     if (isset($_POST['Tenant'])) {
         $model->attributes = $_POST['Tenant'];
         if ($model->validate() && $model->save()) {
             echo CJSON::encode(array('status' => 'success', 'message' => 'Data tenant has been saved successfully !'));
         } else {
             $error = CActiveForm::validate($model);
             if ($error != '[]') {
                 echo $error;
             }
         }
         Yii::app()->end();
     }
     $this->renderPartial('_form', array('model' => $model, false, true));
 }
 public function addUser()
 {
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $this->validationRules);
     if ($validator->fails()) {
         if ($validator->messages()->first('email')) {
             $note = array('error' => true, 'message' => $validator->messages()->first('email'));
         } else {
             if ($validator->messages()->first('password')) {
                 $note = array('error' => true, 'message' => $validator->messages()->first('password'));
             } else {
                 if ($validator->messages()->first('phone')) {
                     $note = array('error' => true, 'message' => $validator->messages()->first('phone'));
                 } else {
                     if ($validator->messages()->first('password_confirm')) {
                         $note = array('error' => true, 'message' => $validator->messages()->first('password_confirm'));
                     }
                 }
             }
         }
         return $note;
         //return Redirect::back()->withInput()->withErrors($validator);
     } else {
         // Get the inputs, with some exceptions
         $inputs = Input::except('password_confirm', 'agent_id', 'group_id');
         // Was the user created?
         if ($user = Sentry::getUserProvider()->create($inputs)) {
             $groupId = Input::get("group_id");
             $group = Sentry::getGroupProvider()->findById($groupId);
             $user->addGroup($group);
             $mail = Input::get('email');
             $getu_id = \User::where('email', $mail)->first();
             $user_id = $getu_id->id;
             $agent_id = Input::get("agent_id");
             $getu_id->created_by = $agent_id;
             $getu_id->created_by = $agent_id;
             $getu_id->update();
             $passwordlogin = Input::get('password');
             $maillogin = Input::get('email');
             $fname = Input::get('first_name');
             $to = Input::get('phone');
             if ($groupId == 3) {
                 $user->addGroup($group);
                 $tenant = new \Tenant();
                 $tenant->tenant_id = $user_id;
                 $tenant->agent_id = $agent_id;
                 $tenant->name = Input::get('first_name');
                 $tenant->lname = Input::get('last_name');
                 $tenant->phone = Input::get('phone');
                 $tenant->email = $mail;
                 $tenant->save();
                 $message = 'Hi ' . $fname . ' your  tenant account on Mteja  has been created successful.';
                 Queue::push('SendSMS', array('message' => $message, 'number' => $to));
                 $note2 = array('error' => false, 'message' => "Tenant Created Successfully");
                 return $note2;
             } else {
                 if ($groupId == 1) {
                     $user->addGroup($group);
                     $owner = new \Owner();
                     $owner->owner_id = $user_id;
                     $owner->agent_id = $agent_id;
                     $owner->name = Input::get('first_name');
                     $owner->lname = Input::get('last_name');
                     $owner->phone = Input::get('phone');
                     $owner->activated = 0;
                     $owner->email = $mail;
                     $owner->save();
                     $codeAct = rand(100000, 999999);
                     $message = 'Hi ' . $fname . ' your Mteja account as an owner has been created successful.Activation code ' . $codeAct;
                     Queue::push('SendSMS', array('message' => $message, 'number' => $to));
                     $note3 = array('error' => false, 'message' => "Account Created Successfully You will be receiving an SMS with activation key shortly.");
                     return $note3;
                 }
             }
         } else {
             $note4 = array('error' => true, 'message' => " Account not  Created try again");
             return $note4;
         }
     }
 }
Exemple #3
0
 /**
  * User create form processing.
  *
  * @return Redirect
  */
 public function postCreate()
 {
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $this->validationRules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return Redirect::back()->withInput()->withErrors($validator);
     }
     try {
         // We need to reverse the UI specific logic for our
         // permissions here before we create the user.
         $permissions = Input::get('permissions', array());
         $this->decodePermissions($permissions);
         app('request')->request->set('permissions', $permissions);
         // Get the inputs, with some exceptions
         $inputs = Input::except('csrf_token', 'password_confirm', 'groups');
         // Was the user created?
         if ($user = Sentry::getUserProvider()->create($inputs)) {
             // Assign the selected groups to this user
             foreach (Input::get('groups', array()) as $groupId) {
                 $group = Sentry::getGroupProvider()->findById($groupId);
                 $user->addGroup($group);
                 $mail = Input::get('email');
                 $getu_id = \User::where('email', $mail)->first();
                 $user_id = $getu_id->id;
                 $agent_id = Sentry::getUser()->id;
                 $getu_id->created_by = $agent_id;
                 $getu_id->update();
                 $passwordlogin = Input::get('password');
                 $maillogin = Input::get('email');
                 $fname = Input::get('first_name');
                 $to = Input::get('phone');
                 $message = ' Hi ' . $fname . ' Your Web ' . $group->name . ' username is ' . $maillogin . ' and the  password: '******'.To logon  Visit  mteja.co.ke ';
                 \LaravelAtApi::sendMessage($to, $message);
                 if ($groupId == 3) {
                     $user->addGroup($group);
                     $tenant = new \Tenant();
                     $tenant->tenant_id = $user_id;
                     $tenant->agent_id = $agent_id;
                     $tenant->name = Input::get('first_name');
                     $tenant->lname = Input::get('last_name');
                     $tenant->phone = Input::get('phone');
                     $tenant->email = $mail;
                     $tenant->save();
                 } else {
                     if ($groupId == 1) {
                         $user->addGroup($group);
                         $owner = new \Owner();
                         $owner->owner_id = $user_id;
                         $owner->agent_id = $agent_id;
                         $owner->name = Input::get('first_name');
                         $owner->lname = Input::get('last_name');
                         $owner->phone = Input::get('phone');
                         $owner->email = $mail;
                         $owner->save();
                     }
                 }
             }
             // Prepare the success message
             $success = Lang::get('admin/users/message.success.create');
             // Redirect to the new user page
             return Redirect::route('admin.invoice.index', $user->id)->withFlashMessage($group->name . ' Created successfully');
         }
         // Prepare the error message
         $error = Lang::get('admin/users/message.error.create');
         // Redirect to the user creation page
         return Redirect::route('create/user')->with('error', $error);
     } catch (LoginRequiredException $e) {
         $error = Lang::get('admin/users/message.user_login_required');
     } catch (PasswordRequiredException $e) {
         $error = Lang::get('admin/users/message.user_password_required');
     } catch (UserExistsException $e) {
         $error = Lang::get('admin/users/message.user_exists');
     }
     // Redirect to the user creation page
     return Redirect::route('create/user')->withInput()->with('error', $error);
 }