user.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. Bugs::actions(
  3. 'user_update'
  4. );
  5. Router::paths(array(
  6. '/~{user}'=>function($res,$args){
  7. $user = Bugs::user($args->user);
  8. if($user->active){
  9. $res->write(
  10. Bugs::template('user')
  11. ->run($user)
  12. );
  13. }else{
  14. trigger_error("User {$args->user} is inactive");
  15. }
  16. },
  17. '/user/{user}'=>function($res,$args){
  18. Router::redirect(Router::url(Router::$base.'/~'.$args->user));
  19. },
  20. '/user/{user}/update'=>function($res,$args){
  21. if(Bugs::$user){
  22. if(!empty($_POST['password'])&&!empty($_POST['id'])&&!empty($_POST['name'])&&!empty($_POST['email'])){
  23. $user = Bugs::user(intval($args->user));
  24. if($user->password == $user->hash($_POST['password'])){
  25. $user->name = $_POST['name'];
  26. $user->email = $_POST['email'];
  27. $res->json(array(
  28. 'name'=>$user->name
  29. ));
  30. if($user->id == Bugs::$user->id){
  31. Bugs::login($user,$_POST['password']);
  32. }
  33. Bugs::activity('user_update',$_POST['name'].' has updated their profile.');
  34. }else{
  35. $res->json(array(
  36. 'error'=>'Invalid password.'
  37. ));
  38. }
  39. }else{
  40. $res->json(array(
  41. 'error'=>'Missing information.'
  42. ));
  43. }
  44. }else{
  45. $res->json(array(
  46. 'error'=>'Not logged in.'
  47. ));
  48. }
  49. }
  50. ));
  51. ?>