public static function createUser($attributes, $isSocAuth = false) { $model = new User(); $model->attributes = $attributes; if (!isset($model->password) || !$model->password) { $password = $model->randomString(); $model->setPassword($password); } else { $password = $model->password; $model->setPassword(); } if ($isSocAuth || param('user_registrationMode') == 'without_confirm') { $model->active = 1; } if ($model->save()) { return array('id' => $model->id, 'email' => $model->email, 'username' => $model->username, 'password' => $password, 'active' => $model->active, 'activatekey' => $model->activatekey, 'activateLink' => Yii::app()->createAbsoluteUrl('/site/activation?key=' . $model->activatekey), 'userModel' => $model); } else { if ($isSocAuth) { $errors = $model->getErrors(); if ($errors) { foreach ($errors as $error) { if ($error && is_array($error)) { foreach ($error as $item) { echo '<div class="alert alert-block alert-error fade in">' . $item . '</div>'; } } } } exit; } else { return false; } } }
public function createUser($email, $username = '', $phone = '', $activateKey = '', $isActive = false) { $model = new User(); $model->email = $email; if ($username) { $model->username = $username; } if ($phone) { $model->phone = $phone; } if ($isActive) { $model->active = 1; } if ($activateKey) { $model->activatekey = $activateKey; } $password = $model->randomString(); $model->setPassword($password); $return = array(); if ($model->save()) { $return = array('email' => $model->email, 'username' => $model->username, 'password' => $password, 'id' => $model->id, 'active' => $model->active, 'activateKey' => $activateKey, 'activateLink' => Yii::app()->createAbsoluteUrl('/site/activation', array('key' => $activateKey))); } return $return; }
public function actionAdd() { $model = new User(); $store = Store::model()->findAll('i_account_manager = 0'); $typeAccount = Yii::app()->user->hasState('typeAccountCurrent') ? Yii::app()->user->getState('typeAccountCurrent') : null; $this->pageTitle = $typeAccount != null ? 'Add Account Of ' . $typeAccount : 'Add Account'; if (isset(Yii::app()->user->storeID)) { $model->s_store_id = Yii::app()->user->storeID; $store = null; } if (isset($_POST['User'])) { $flagSave = false; $pk_s_id = 0; $s_image_server = ''; $password = ''; $model->attributes = $_POST['User']; $model->pk_s_id = '-1'; $levelAccount = Yii::app()->user->level; $role = Roles::model()->findByPk($model->i_user_role); $checkStore = Store::model()->find('pk_s_id = :pk_s_id', array(':pk_s_id' => $model->s_store_id)); //var_dump($checkStore);exit; $model->i_manager = 0; $model->i_device_max = intval($model->i_device_max); $model->s_code_active = $model->randomString(time() . 'ABCDEFGHIJKLM' . time() . time(), 8); $model->s_token = sha1(base64_encode($model->s_code_active) . time()); $model->i_time_send_code_active = time() + 86400; $model->s_secret_code = $model->secretCode(); $model->i_active = 0; $model->i_lock = 0; $model->i_flag_sync = 1; $model->i_flag_deleted = 0; $model->i_disable = 0; if ($model->i_user_role == 3) { $model->i_manager = 1; } if ($checkStore == null) { $model->s_store_id = null; } else { $storeManager = $checkStore->userManager(); if ($storeManager != null) { $model->addError('i_user_role', 'The store has managed. Please select user type other or stores other'); } } if ($role == null) { $model->addError('i_user_role', 'Type not exist'); } elseif ($levelAccount < $role->level) { $model->addError('i_user_role', 'Your are not authorized to make this type of account'); } $image = CUploadedFile::getInstance($model, 's_image_server'); if ($image != null) { $model->s_image_server = $model->s_username . date("dmHi") . '.' . $image->extensionName; if ($image->saveAs(Yii::app()->basePath . '/../data/users/' . $model->s_image_server)) { $imgthumb = Yii::app()->phpThumb->create(Yii::app()->basePath . '/../data/users/' . $model->s_image_server); $imgthumb->resize(240, 240); $imgthumb->save(Yii::app()->basePath . '/../data/users/240x240_' . $model->s_image_server); $imgthumb->resize(120, 120); $imgthumb->save(Yii::app()->basePath . '/../data/users/120x120_' . $model->s_image_server); $model->i_sync_image = 1; } else { $model->addError('s_image_server', 'Upload image fail'); } } if (count($model->errors) == 0) { if ($model->save()) { $flagSave = true; $pk_s_id = 'SV' . $model->id; $password = sha1($model->s_secret_code . sha1($model->s_password . $model->s_secret_code)); $model->pk_s_id = $pk_s_id; $model->s_password = $password; if ($model->save()) { $flagSave = true; } else { $flagSave = false; @unlink(Yii::app()->basePath . '/../data/users/' . $model->s_image_server); @unlink(Yii::app()->basePath . '/../data/users/240x240_' . $model->s_image_server); @unlink(Yii::app()->basePath . '/../data/users/120x120_' . $model->s_image_server); $model->delete(); } } if ($flagSave == true) { $this->redirect(array('index')); } } } $this->render('create', array('model' => $model, 'store' => $store, 'typeAccount' => $typeAccount)); }