예제 #1
0
 /**
  * Signs user up.
  *
  * @return Member|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $connection = yii::$app->db;
         $transaction = $connection->beginTransaction();
         $pw = $this->password;
         try {
             $member = new Member();
             $member->email = $this->email;
             $member->setPassword($pw);
             $member->generateAuthKey();
             $member->beforeSave(TRUE);
             $member->save();
             $member_profile = new MemberProfile();
             $member_profile->name = $this->name;
             $member_profile->address = $this->address;
             $member_profile->contact_number = $this->contact_number;
             $member_profile->member_id = $member->id;
             $member_profile->beforeSave(TRUE);
             $member_profile->save();
             if (1 == $this->is_affiliate) {
                 $affiliate = new ApMembers();
                 $affiliate->email = $member->email;
                 $affiliate->fullname = $this->name;
                 $affiliate->balance = '0.00';
                 $affiliate->terms = '1';
                 $affiliate->password = password_hash($pw, PASSWORD_DEFAULT, ["cost" => 10]);
                 $affiliate->admin_user = '******';
                 $affiliate->browser = $_SERVER['HTTP_USER_AGENT'];
                 $affiliate->referrar_id = $this->referrar_id;
                 $affiliate->save();
             }
             $transaction->commit();
             return $member;
         } catch (Exception $exc) {
             $transaction->rollBack();
             throw $e;
         }
     }
     return null;
 }