Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. public function createUser() {
  3. $username = substr($this->phone, 1);
  4. $criteria = new CDbCriteria();
  5. if (!empty($this->email)) {
  6. $criteria->addCondition('username = ' . db()->quoteValue($username), 'OR');
  7. $criteria->addCondition('email = ' . db()->quoteValue($this->email), 'OR');
  8. } else {
  9. $this->email = 'customer_' . $username . '@banket.ru';
  10. $criteria->addCondition('username = ' . db()->quoteValue($username), 'OR');
  11. $criteria->addCondition('email = ' . db()->quoteValue($this->email), 'OR');
  12. }
  13. $user = User::model()->find($criteria);
  14. if (!$user) {
  15. $user = new User('create');
  16. $user->email = $this->email;
  17. $user->username = $username;
  18. $user->password = uniqid();
  19. if ($user->save()) {
  20. Yii::app()->authManager->assign(UserRoles::CUSTOMER, $user->id);
  21. $profile = new Profile();
  22. $profile->firstname = $this->person;
  23. $profile->phone = $this->phone;
  24. $profile->user_id = $user->id;
  25. $profile->save();
  26. }
  27. }
  28.  
  29. return $user->id;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement