Source code for cock.li
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AuthController.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php namespace App\Http\Controllers\Auth;
  2. use App\Http\Controllers\Controller;
  3. use Illuminate\Contracts\Auth\Guard;
  4. use Illuminate\Contracts\Auth\Registrar;
  5. use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
  6. use Illuminate\Http\Request;
  7. use App\Domain;
  8. use Mail;
  9. use Auth;
  10. class AuthController extends Controller {
  11. /*
  12. |--------------------------------------------------------------------------
  13. | Registration & Login Controller
  14. |--------------------------------------------------------------------------
  15. |
  16. | This controller handles the registration of new users, as well as the
  17. | authentication of existing users. By default, this controller uses
  18. | a simple trait to add these behaviors. Why don't you explore it?
  19. |
  20. */
  21. use AuthenticatesAndRegistersUsers;
  22. /**
  23. * Create a new authentication controller instance.
  24. *
  25. * @param \Illuminate\Contracts\Auth\Guard $auth
  26. * @param \Illuminate\Contracts\Auth\Registrar $registrar
  27. * @return void
  28. */
  29. public function __construct(Guard $auth, Registrar $registrar)
  30. {
  31. $this->auth = $auth;
  32. $this->registrar = $registrar;
  33. $this->redirectTo = "/user/congrats";
  34. $this->middleware('guest', ['except' => 'getLogout']);
  35. }
  36. /**
  37. * Show the application registration form.
  38. *
  39. * @return \Illuminate\Http\Response
  40. */
  41. public function getRegister()
  42. {
  43. return view('auth.register')->with('domains', Domain::where('public',1)->where('open',1)->get());
  44. }
  45. /**
  46. * Handle a registration request for the application.
  47. *
  48. * @param \Illuminate\Http\Request $request
  49. * @return \Illuminate\Http\Response
  50. */
  51. public function postRegister(Request $request)
  52. {
  53. $data = $request->all();
  54. if(isset($data['username']) && isset($data['domain'])) {
  55. $data['username'] = strtolower($data['username']);
  56. $data['email'] = $data['username'] . '@' . $data['domain'];
  57. $data['email'] = strtolower($data['email']);
  58. }
  59. $validator = $this->registrar->validator($data);
  60. if ($validator->fails())
  61. {
  62. $this->throwValidationException(
  63. $request, $validator
  64. );
  65. }
  66. $this->auth->login($this->registrar->create($data));
  67. if(isset($data['news_subscription']) && $data['news_subscription'] === "on" && env('APP_ENV','local') === 'production') {
  68. $un = $data['email'];
  69. `echo "$un" | /usr/lib/mailman/bin/add_members -w n -r - cock.li-news`;
  70. }
  71. if(env('APP_ENV','local') === 'production') {
  72. Mail::send(['text' => 'emails.welcome'], ['username' => Auth::user()->email], function($message){
  73. $message->to(Auth::user()->email)->subject('Welcome to Cockmail!');
  74. });
  75. }
  76. return redirect($this->redirectPath())->with('just_registered',true);
  77. }
  78. }