/** * Creates a new User. */ public function actionCreate() { $user = new YumUser(); if (Yum::hasModule('profile')) { $profile = new YumProfile(); } $passwordform = new YumUserChangePassword(); // When opening a empty user creation mask, we most probably want to // insert an _active_ user if (!$user->status) { $user->status = 1; } if (isset($_POST['YumUser'])) { $user->attributes = $_POST['YumUser']; if (isset($_POST['YumUserChangePassword'])) { if ($_POST['YumUserChangePassword']['password'] == '') { Yii::import('user.components.EPasswordGenerator'); $generatorOptions = Yum::module()->passwordGeneratorOptions; $password = EPasswordGenerator::generate($generatorOptions['length'], $generatorOptions['capitals'], $generatorOptions['numerals'], $generatorOptions['symbols']); $user->setPassword($password); Yum::setFlash(Yum::t('The generated Password is {password}', array('{password}' => $password))); } else { $passwordform->attributes = $_POST['YumUserChangePassword']; if ($passwordform->validate()) { $user->setPassword($_POST['YumUserChangePassword']['password']); } } } $user->validate(); if (Yum::hasModule('profile') && isset($_POST['YumProfile'])) { $profile->attributes = $_POST['YumProfile']; } if (!$user->hasErrors()) { $user->activationKey = CPasswordHelper::hashPassword(microtime() . $user->password, Yum::module()->passwordHashCost); if ($user->username == '' && isset($profile)) { $user->username = $profile->email; } if (isset($profile)) { $profile->validate(); } if (!$user->hasErrors() && !$passwordform->hasErrors()) { $user->save(); if (isset($_POST['YumUser']['roles'])) { $user->syncRoles($_POST['YumUser']['roles']); } else { $user->syncRoles(); } if (isset($profile)) { $profile->user_id = $user->id; $profile->save(array('user_id'), false); } $this->redirect(array('view', 'id' => $user->id)); } } } $this->render('create', array('user' => $user, 'passwordform' => $passwordform, 'profile' => isset($profile) ? $profile : null)); }