Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function createUser() {
- $username = substr($this->phone, 1);
- $criteria = new CDbCriteria();
- if (!empty($this->email)) {
- $criteria->addCondition('username = ' . db()->quoteValue($username), 'OR');
- $criteria->addCondition('email = ' . db()->quoteValue($this->email), 'OR');
- } else {
- $this->email = 'customer_' . $username . '@banket.ru';
- $criteria->addCondition('username = ' . db()->quoteValue($username), 'OR');
- $criteria->addCondition('email = ' . db()->quoteValue($this->email), 'OR');
- }
- $user = User::model()->find($criteria);
- if (!$user) {
- $user = new User('create');
- $user->email = $this->email;
- $user->username = $username;
- $user->password = uniqid();
- if ($user->save()) {
- Yii::app()->authManager->assign(UserRoles::CUSTOMER, $user->id);
- $profile = new Profile();
- $profile->firstname = $this->person;
- $profile->phone = $this->phone;
- $profile->user_id = $user->id;
- $profile->save();
- }
- }
- return $user->id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement