Add multi user support and subscriptions (#359)
This pull request adds support to multi users in one account. It also introduces the notion of subscriptions. Accounts can now have multiple users. Subscriptions are defined by a new env variable called REQUIRES_SUBSCRIPTION, and defaults to false. As promised, all the paid features on .com will be free if you download and host Monica on your own server.
This commit is contained in:
@@ -7,6 +7,7 @@ use App\User;
|
||||
use Socialite;
|
||||
use Validator;
|
||||
use App\Account;
|
||||
use Carbon\Carbon;
|
||||
use App\Helpers\RandomHelper;
|
||||
use App\Jobs\SendNewUserAlert;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -88,11 +89,13 @@ class RegisterController extends Controller
|
||||
$user->email = $data['email'];
|
||||
$user->password = bcrypt($data['password']);
|
||||
$user->timezone = config('app.timezone');
|
||||
$user->created_at = Carbon::now();
|
||||
$user->save();
|
||||
|
||||
// create a new account
|
||||
$account = new Account;
|
||||
$account->api_key = RandomHelper::generateString(30);
|
||||
$account->created_at = Carbon::now();
|
||||
$account->save();
|
||||
|
||||
$user->account_id = $account->id;
|
||||
@@ -103,58 +106,4 @@ class RegisterController extends Controller
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user to the Facebook authentication page.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function redirectToProvider()
|
||||
{
|
||||
return Socialite::driver('facebook')->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the user information from Facebook.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handleProviderCallback()
|
||||
{
|
||||
$user = Socialite::driver('facebook')->user();
|
||||
|
||||
// Is there a user already registered?
|
||||
$userObject = User::where('email', $user->getEmail())->first();
|
||||
|
||||
if (count($userObject) == 0) {
|
||||
|
||||
// Abort if signup is disabled
|
||||
if (env('APP_DISABLE_SIGNUP') == 'true') {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$userObject = new User;
|
||||
$userObject->first_name = 'Facebook';
|
||||
$userObject->last_name = 'User';
|
||||
$userObject->email = $user->getEmail();
|
||||
$userObject->timezone = config('app.timezone');
|
||||
$userObject->save();
|
||||
|
||||
// create a new account
|
||||
$account = new Account;
|
||||
$account->api_key = RandomHelper::generateString(30);
|
||||
$account->save();
|
||||
|
||||
$userObject->account_id = $account->id;
|
||||
$userObject->access_token = $user->token;
|
||||
$userObject->save();
|
||||
|
||||
// send me an alert
|
||||
dispatch(new SendNewUserAlert($userObject));
|
||||
}
|
||||
|
||||
Auth::login($userObject);
|
||||
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user