Ejemplo n.º 1
0
 /**
  * Signs user up.
  *
  * @return Users|null the saved model or null if saving fails
  */
 public function register()
 {
     $user = null;
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $group = new Groups();
         $group->name = $this->email;
         if ($group->save()) {
             $user = parent::register($group->id);
             for ($i = 0; $i < $this->beacon_count; $i++) {
                 $beacon = new Beacons();
                 $beacon->name = Yii::$app->security->generateRandomString(16);
                 $beacon->title = "Such title {$i}";
                 $beacon->description = "So description {$i}";
                 $beacon->minor = $group->id . $user->id . $i;
                 $beacon->major = $group->id . $user->id . $i;
                 $beacon->place = "Wow Place {$i}";
                 $beacon->uuid = UUID::v4();
                 $beacon->groupToBind = $group->id;
                 $beacon->save();
             }
         }
         $transaction->commit();
         return $user;
     } catch (Exception $e) {
         if ($transaction->isActive) {
             $transaction->rollBack();
         }
         return null;
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Groups model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Groups();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates a new Groups model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Groups();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('group-form', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 /**
  * render Creategroup.php with $model = new Groups();
  * 
  * @return $this->render('signup', ['model' => $model])
  */
 public function actionCreategroup()
 {
     $user = $this->getUser();
     $group = new Groups();
     $group->l_user = $user->username;
     $group->create_date = date("Y-m-d");
     $group->status = 'o';
     if ($group->load(Yii::$app->request->post()) && $group->validate()) {
         if (!$group->groupExist()) {
             if ($group->save()) {
                 return $this->goHome();
             } else {
                 return $this->render('say', ['message' => 'GroupErr']);
             }
         } else {
             return $this->render('error', ['name' => 'error', 'message' => "You Created this group {$group->groupname}..."]);
         }
     }
     return $this->render('creategroup', ['model' => $group]);
 }
Ejemplo n.º 5
0
 public function postCreate(Request $request)
 {
     $email = $request->input('email');
     $password = $request->input('password');
     $group_to_register_in = $request->input('group_to_register_in');
     $validator = validator::make($request->all(), ['email' => 'required|unique:users|email', 'password' => 'required|max:16|min:6', 'password_again' => 'required|same:password', 'group_to_register_in' => 'required|in:1,2,3']);
     $account_sign_in_route = null;
     $account_create_route = null;
     if ($request->is(RequiredConstants::ADMIN_ROUTE)) {
         $account_create_route = route('account-admin-create');
         $account_sign_in_route = route('account-admin-sign-in');
     } elseif ($request->is(RequiredConstants::USER_ROUTE)) {
         $account_create_route = route('account-user-create');
         $account_sign_in_route = route('account-user-sign-in');
     }
     if ($validator->fails()) {
         $flash_data = 'You have some errors !!';
         return redirect($account_create_route)->withErrors($validator->errors())->withInput()->withGlobal($flash_data);
     }
     $group_id = null;
     if ($group_to_register_in == Groups::Student_Group_Id) {
         $group_id = Groups::Student_Group_Id;
     } elseif ($group_to_register_in == Groups::Administrator_Group_ID) {
         $group_id = Groups::Administrator_Group_ID;
     } elseif ($group_to_register_in == Groups::Teacher_Group_Id) {
         $group_id = Groups::Teacher_Group_Id;
     }
     DB::beginTransaction();
     try {
         Groups::findorFail($group_id);
         $user = new User();
         $user->email = $email;
         $user->password = Hash::make($password);
         $user->activated = 0;
         $user->email_updated_at = date("Y-m-d h:i:s");
         $user->password_updated_at = date("Y-m-d h:i:s");
         $user->activation_code = str_random(64);
         if (!$user->save()) {
             throw new \ErrorException();
         }
         $user_group = new UserGroup();
         $user_group->user_id = $user->id;
         $user_group->group_id = $group_id;
         if (!$user_group->save()) {
             throw new \ErrorException();
         }
         DB::commit();
     } catch (ModelNotFoundException $e) {
         DB::rollback();
         $groups = new Groups();
         $groups->id = 1;
         $groups->name = "Administrator";
         $groups->save();
         $groups = new Groups();
         $groups->id = 2;
         $groups->name = "Student";
         $groups->save();
         $groups = new Groups();
         $groups->id = 3;
         $groups->name = "Teacher";
         $groups->save();
         $flash_data = 'You have some errors!!';
         return redirect($account_create_route)->withInput()->withGlobal($flash_data);
     } catch (\ErrorException $e) {
         DB::rollback();
         $flash_data = 'You have some errors!!';
         return redirect($account_create_route)->withInput()->withGlobal($flash_data);
     }
     // Send mail to the user if not the test Shop Id.
     $email_array = [];
     if (!RequiredFunctions::checkIfTestEmail($email)) {
         //send email
         Mail::send('schools.emails.activate-school', $email_array, function ($message) use($user) {
             $message->to($user->email, 'Mr. Admin')->subject('Register For Admin and Other Codes');
         });
     }
     $flash_data = 'You have Successfully Registered. You have been send an email. Please Activate!!';
     return redirect($account_sign_in_route)->withGlobal($flash_data);
 }
Ejemplo n.º 6
0
 public function getIdGroup($groupId)
 {
     $group = Groups::where('identifiant', '=', $groupId)->first();
     if (!$group) {
         $responseGroup = $this->getGroup($groupId);
         $group = new Groups();
         $group->identifiant = $groupId;
         $group->nom = $responseGroup['name'];
         $group->save();
     }
     return $group->id_Groups;
 }