HelloController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace app\commands;
  8. use app\models\User;
  9. use yii\console\Controller;
  10. use yii\console\ExitCode;
  11. /**
  12. * This command echoes the first argument that you have entered.
  13. *
  14. * This command is provided as an example for you to learn how to create console commands.
  15. *
  16. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @since 2.0
  18. */
  19. class HelloController extends Controller
  20. {
  21. /**
  22. * This command echoes what you have entered as the message.
  23. * @param string $message the message to be echoed.
  24. * @return int Exit code
  25. */
  26. public function actionIndex($message = 'hello world')
  27. {
  28. echo $message . "\n";
  29. return ExitCode::OK;
  30. }
  31. public function actionCreateUser($username,$password)
  32. {
  33. $user = new User();
  34. $user->username = $username;
  35. $user->resetPassword($password);
  36. $user->save();
  37. }
  38. public function actionChangePassword($username, $password)
  39. {
  40. $user = User::findByUsername($username);
  41. $user->resetPassword($password);
  42. $user->save();
  43. }
  44. }