public function up() { $AdminUser = new User(); $AdminUser->generateAuthKey(); $AdminUser->setAttribute('username', 'admin'); //$AdminUser->setAttribute('auth_key', 'admin'); $AdminUser->setPassword('admin'); $AdminUser->setAttribute('email', '*****@*****.**'); if ($AdminUser->save()) { return true; } else { return false; } }
/** * 更新用户信息 * @return boolean */ public function update(User $user) { $pre_username = $user->username; $user->setAttributes($this->attributes); if ($pre_username != $user->wangwang) { $user->setAttribute("username", $pre_username); } return $user->update(); }
public static function addUser($weixinUser) { #注册新用户 $newuser = new User(); $newuser->setAttribute('username', $weixinUser); $newuser->setAttribute('password', $newuser->generatePassword(self::generateRandString())); $newuser->setAttribute('wangwang', $weixinUser); if ($newuser->validate() && $newuser->save()) { $accountarray = array('user_id' => \Yii::$app->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0); $newAccount = new Account(); $newAccount->setAttributes($accountarray); $newAccount->save(); } $user = User::find()->where("username=:username", [":username" => $weixinUser])->one(); return $user; }