Example #1
0
 public function actionSignup()
 {
     $signup = new SignupForm(['scenario' => 'signup']);
     $user = new User();
     $signup->email = Yii::$app->request->post('email');
     $signup->password = Yii::$app->request->post('password');
     $signup->display_name = Yii::$app->request->post('display_name');
     if ($user = $signup->signup()) {
         $user->role = User::ROLE_USER;
         $user->save();
         return json_encode(['success' => true, 'data' => $user->attributes]);
     } else {
         if ($signup->hasErrors()) {
             return json_encode(['success' => false, 'data' => $signup->getErrors()]);
         }
     }
 }