controllers/AppController.php
/**
     * Creates a new Users model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Users model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Users model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new User();
        if ($model->load(Yii::$app->request->post())){
            $str=rand(); 
            $passwordnormal = uniqid();
            $model->authKey = $str.trim($model->id);
            $model->activo = 1;
            $model->password = Yii::$app->getSecurity()->generatePasswordHash($passwordnormal);
            if ($model->save()) {
                try {
                    Yii::$app->mailer->compose(['html' => '@app/mail/newuser'], ['password' => $passwordnormal, 'id' => $model->id, ])
                        ->setFrom('contacto@villaluz.com.mx')
                        ->setTo($model->email)
                        ->setSubject('Nuevo usuario creado en Villaluz')
                        ->send();
                } catch (\ErrorException $e) {
                    Yii::$app->session->setFlash('error', 'Usuario Creado pero el email no fue enviado'. $e->getMessage());
                }
                return $this->redirect(['show']);
            }
        }  
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new User ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ str = rand ( ) ; $ passwordnormal = uniqid ( ) ; $ model -> authKey = $ str . trim ( $ model -> id ) ; $ model -> activo = 1 ; $ model -> password = Yii :: $ app -> getSecurity ( ) -> generatePasswordHash ( $ passwordnormal ) ; if ( $ model -> save ( ) ) { try { Yii :: $ app -> mailer -> compose ( [ 'html' => '@app/mail/newuser' ] , [ 'password' => $ passwordnormal , 'id' => $ model -> id , ] ) -> setFrom ( 'contacto@villaluz.com.mx' ) -> setTo ( $ model -> email ) -> setSubject ( 'Nuevo usuario creado en Villaluz' ) -> send ( ) ; } catch ( \ ErrorException $ e ) { Yii :: $ app -> session -> setFlash ( 'error' , 'Usuario Creado pero el email no fue enviado' . $ e -> getMessage ( ) ) ; } return $ this -> redirect ( [ 'show' ] ) ; } } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Users model.
Creates a new Users model .