Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new GroupMember();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['GroupMember'])) {
         $model->attributes = $_POST['GroupMember'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 public function actionInvite($invite_id, $accept)
 {
     $invite = GroupInvite::model()->findByPk($invite_id);
     if (!$invite) {
         throw new CHttpException(404);
     }
     $invite->setAttribute('status', $accept == 1 ? GroupInvite::INVITE_ACCEPT : GroupInvite::INVITE_CANCELED);
     if ($accept == 1) {
         $group_member = new GroupMember();
         $group_member->setAttributes(['group_id' => $invite->group_id, 'user_id' => Yii::app()->user->getId()]);
         $group_member->save();
     }
     if ($invite->save()) {
         Yii::app()->user->setFlash('success', 'Приглашение ' . ($accept == 1 ? 'принято' : 'отклонено'));
     } else {
         Yii::app()->user->setFlash('error', 'Произошла ошибка');
     }
     $this->redirect(['notifications']);
 }
Пример #3
0
 /**
  * 新加入一个用户
  *  @param unknown_type $userId
  */
 public function addMember($userId, $roles = array())
 {
     $owner = $this->getOwner();
     $member = GroupMember::model()->findByAttributes(array('memberableEntityId' => $owner->entityId, 'userId' => $userId));
     if (!$roles) {
         $roles = $this->getDefaultRoles();
     }
     if (!$member) {
         //插入一条新数据
         $member = new GroupMember();
         $member->userId = $userId;
         $member->memberableEntityId = $owner->entityId;
         $member->addTime = time();
         $member->setArrRoles($roles);
         $result = $member->save();
         $this->onAdded(new CEvent());
         return $result;
     }
     return false;
 }
Пример #4
0
 public function processMemberInvite($groupId)
 {
     $group = Group::where('id', '=', $groupId)->first();
     if (!$group) {
         return Response::json($this->growlMessage('Invalid Group ID', 'error'));
     }
     if (!$group->isGroupOwner(Auth::user()->id)) {
         return Response::json($this->growlMessage('You cannot add people to a group unless you are the group owner', 'error'));
     }
     $email = Input::all()['email'];
     $role = Input::all()['role'];
     if (!Group::isValidRole($role)) {
         return Response::json($this->growlMessage('Invalid role type.', 'error'));
     }
     $user = User::where('email', '=', $email)->first();
     if (!$user) {
         return Response::json($this->growlMessage('Invalid user', 'error'));
     }
     $userExists = (bool) GroupMember::where('user_id', '=', $user->id)->where('group_id', '=', $group->id)->count();
     if ($userExists) {
         return Response::json($this->growlMessage('This user is already a member of the group!', 'error'));
     }
     $newMember = new GroupMember();
     $newMember->user_id = $user->id;
     $newMember->group_id = $group->id;
     $newMember->role = $role;
     $newMember->save();
     $text = "You've been added to the group " . $group->getDisplayName() . " with the role of " . $role . ".";
     // Notify member of invite
     Mail::queue('email.notification', array('text' => $text), function ($message) use($email) {
         $message->subject("You've been added to a Madison group");
         $message->from('*****@*****.**', 'Madison');
         $message->to($email);
     });
     return Response::json($this->growlMessage('User added successfully', 'success'));
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     $org = new Organisation();
     // ajax validator
     //if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form')
     //{
     //        echo UActiveForm::validate(array($model,$profile));
     //        Yii::app()->end();
     //}
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         if ($_POST['RegistrationForm']['service'] == 2) {
             ////////////////////////////////////////////////////////////////////////////////
             //$name = trim($org->name);
             $name = trim($_POST['Organisation']['name']);
             $exOrgCount = Organisation::model()->count('name=:param_name', array(':param_name' => $name));
             if ($exOrgCount > 0) {
                 $org->validatorList->add(CValidator::createValidator('unique', $org, 'name', array('message' => Yii::t('app', 'Group Name already exists'))));
             } else {
                 if (strlen($name) == 0) {
                     $org->validatorList->add(CValidator::createValidator('required', $org, 'name', array('message' => Yii::t('app', 'Group Name canot be blank'))));
                 }
             }
             ////////////////////////////////////////////////////////////////////////////////
             echo UActiveForm::validate(array($model, $profile, $org));
             Yii::app()->end();
         } else {
             echo UActiveForm::validate(array($model, $profile));
             Yii::app()->end();
         }
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             $valid = $model->validate();
             $valid = $profile->validate() && $valid;
             if ($_POST['RegistrationForm']['service'] == 2) {
                 $org->name = trim($_POST['Organisation']['name']);
                 $valid = $org->validate() && $valid;
             }
             //if($model->validate()&&$profile->validate())
             if ($valid) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 $orgDuplicateCheck = false;
                 $flag = true;
                 $role = 'Authenticated';
                 if ($model->service == 1) {
                     $orgDuplicateCheck = true;
                     $role = 'Individual';
                 } else {
                     if ($model->service == 2 && isset($_POST['Organisation']['name'])) {
                         $org->name = trim($_POST['Organisation']['name']);
                         $flag = Organisation::model()->exists('name=:param_name_check', array(':param_name_check' => $org->name));
                         if (!$flag) {
                             $orgDuplicateCheck = true;
                         }
                         $role = 'Org_Admin';
                     } else {
                         //$org->validatorList->add(CValidator::createValidator('unique', $org, 'name', array('message'=>Yii::t('app','Group Name Already Exists'))));
                         $org->validate();
                         Yii::app()->user->setFlash('registration', UserModule::t("Group Name already exists"));
                     }
                 }
                 if ($orgDuplicateCheck) {
                     if ($model->save()) {
                         $profile->user_id = $model->id;
                         $profile->firstname = $model->firstname;
                         $profile->lastname = $model->lastname;
                         $profile->save();
                         $this->assignRole($model->id, $role);
                         //If Service=2 ~ Organisation Save New (Non-Existent) Organisation
                         if (!$flag) {
                             $org->created_by = $model->id;
                             $org->type = 'Other';
                             //$org->timestamp_create = date('Y-m-d H:i:s');
                             if ($org->save()) {
                                 $model->organisation_id = $org->id;
                                 $model->organisation_administrator = 1;
                                 $model->save(false);
                                 try {
                                     //Create Organisation Group
                                     $group = new Group();
                                     $group->group_name = $org->name;
                                     $group->parent_group_id = 0;
                                     $group->organisation_id = $org->id;
                                     $group->timestamp_created = date('Y-m-d H:i":');
                                     $group->save(false);
                                     $groupMember = new GroupMember();
                                     $groupMember->group_id = $group->group_id;
                                     $groupMember->user_id = $model->id;
                                     $groupMember->manager_flag = 1;
                                     //$groupMember->created_by = 0;
                                     //$groupMember->timestamp_created = date('Y-m-d H:i:s');
                                     $groupMember->save(false);
                                 } catch (Exception $ex) {
                                     Yii::log($ex->getMessage(), 'error', 'Custom');
                                 }
                             } else {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Oop! Soemthing Went Wrong"));
                             }
                         }
                         if (Yii::app()->controller->module->sendActivationMail) {
                             $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                             UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate your account by going to {activation_url}", array('{activation_url}' => $activation_url)));
                         }
                         if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                             $identity = new UserIdentity($model->username, $soucePassword);
                             $identity->authenticate();
                             Yii::app()->user->login($identity, 0);
                             $this->redirect(Yii::app()->controller->module->returnUrl);
                         } else {
                             if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                             } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                             } elseif (Yii::app()->controller->module->loginNotActiv) {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email to login."));
                             } else {
                                 //Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email."));
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your spam/junk folder if you email is not in inbox."));
                             }
                             $this->refresh();
                         }
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile, 'org' => $org));
     }
 }
Пример #6
0
 public function addMember($userId, $role = null)
 {
     $groupMember = $this->findMemberByUserId($userId);
     if (!$groupMember) {
         if (is_null($role)) {
             throw new \Exception("You must provide a role if adding a new member");
         }
         if (!isset($this->id) || empty($this->id)) {
             throw new \Exception("The group must have a ID set in order to add a member");
         }
         $groupMember = new GroupMember();
         $groupMember->user_id = $userId;
         $groupMember->role = Group::ROLE_OWNER;
         $groupMember->group_id = $this->id;
     } else {
         if (!is_null($role)) {
             $groupMember->role = $role;
         }
     }
     $groupMember->save();
 }
Пример #7
0
 /**
  * 创建小组页面和处理
  */
 public function actionCreate()
 {
     $model = new Group();
     if (isset($_POST['Group'])) {
         $model->attributes = $_POST['Group'];
         $model->addTime = time();
         $model->userId = Yii::app()->user->id;
         $model->status = "apply";
         if ($model->save()) {
             //			$model->addMember(Yii::app()->user->id,array('superAdmin'));
             $member = new GroupMember();
             $member->groupId = $model->id;
             $member->userId = Yii::app()->user->id;
             $member->setArrRoles(array('superAdmin'));
             $member->save();
             $admins = UserInfo::getAllAdmins();
             foreach ($admins as $user) {
                 Notice::send($user->id, 'group_apply', array('groupId' => $model->getPrimaryKey()));
             }
             Yii::app()->user->setFlash('success', '申请已提交,请继续完善小组资料');
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $user = UserInfo::model()->findByPk(Yii::app()->user->id);
     $this->render('create', array('model' => $model, 'user' => $user));
 }
Пример #8
0
 public function actionInvite($hash, $type = 1)
 {
     if (!in_array($type, [1, 2])) {
         throw new CHttpException(404, 'Данный тип не существует');
     }
     if ($type == 1) {
         $invite = GroupInvite::model()->with('group')->findByAttributes(['status' => GroupInvite::INVITE_CREATE, 'hash' => $hash]);
     } elseif ($type == 2) {
         $invite = Invite::model()->findByAttributes(['status' => Invite::INVITE_ACCEPT, 'hash' => $hash]);
     }
     if (!isset($invite)) {
         throw new CHttpException(404, 'Данное приглашение не найдено или было отменено');
     }
     $model = new Users();
     if (Yii::app()->request->isPostRequest) {
         $user = Yii::app()->request->getParam('Users');
         $model->setAttributes($user);
         $model->setAttributes(['email' => $invite->email, 'password' => md5($user['password'])]);
         if ($model->save()) {
             Yii::app()->authManager->assign('user', $model->id);
             $user_identity = new UserIdentity($model->username, $model->password);
             $user_identity->authenticate();
             Yii::app()->user->login($user_identity, 60 * 60 * 24 * 7);
             switch ($type) {
                 case 1:
                     $invite->setAttribute('status', GroupInvite::INVITE_ACCEPT);
                     $invite->save();
                     $group_member = new GroupMember();
                     $group_member->setAttributes(['group_id' => $invite->group_id, 'user_id' => $model->id]);
                     $group_member->save();
                     break;
                 case 2:
                     $invite->setAttribute('status', Invite::INVITE_USED);
                     $invite->save(false);
                     $group = new Group();
                     $group->setAttributes(['number' => $invite->group_number, 'owner_id' => $model->id]);
                     $group->save();
             }
             $this->redirect(['site/dashboard']);
         }
     }
     $this->render('invite', ['model' => $model]);
 }