mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 23:01:29 +00:00
Update invite code
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
2019-08-06 DariusIII
|
||||
* Chg: Update invite code
|
||||
2019-08-05 DariusIII
|
||||
* Chg: Fix sending invites when site is in invite mode
|
||||
2019-08-04 DariusIII
|
||||
|
||||
@@ -7,6 +7,10 @@ use Illuminate\Http\Request;
|
||||
|
||||
class AjaxController extends BasePageController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function profile(Request $request)
|
||||
{
|
||||
$this->setPrefs();
|
||||
|
||||
@@ -5,10 +5,14 @@ namespace App\Http\Controllers\Auth;
|
||||
use App\Models\User;
|
||||
use App\Models\Settings;
|
||||
use App\Models\Invitation;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Blacklight\utility\Utility;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Junaidnasir\Larainvite\Facades\Invite;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
@@ -50,9 +54,7 @@ class RegisterController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return \App\Models\User
|
||||
*/
|
||||
protected function create(array $data): User
|
||||
@@ -73,14 +75,14 @@ class RegisterController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @return RedirectResponse|Redirector|void
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
$error = $userName = $password = $confirmPassword = $email = $inviteCode = $inviteCodeQuery = '';
|
||||
$error = $userName = $password = $confirmPassword = $email = $inviteCode = '';
|
||||
$showRegister = 1;
|
||||
|
||||
if ($request->has('invitecode')) {
|
||||
@@ -102,73 +104,61 @@ class RegisterController extends Controller
|
||||
if ($validator->fails()) {
|
||||
$error = implode('', Arr::collapse($validator->errors()->toArray()));
|
||||
|
||||
return $this->showRegistrationForm($error);
|
||||
return $this->showRegistrationForm($request, $error);
|
||||
}
|
||||
|
||||
if (Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE && (! $request->has('invitecode') || empty($request->input('invitecode')))) {
|
||||
/*if (empty($inviteCode) && (int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE) {
|
||||
$error = 'Registrations are currently invite only.';
|
||||
$showRegister = 0;
|
||||
|
||||
return $this->showRegistrationForm($error);
|
||||
}
|
||||
return $this->showRegistrationForm($request, $error, $showRegister);
|
||||
}*/
|
||||
|
||||
if ($showRegister === 1) {
|
||||
$action = $request->input('action') ?? 'view';
|
||||
|
||||
switch ($action) {
|
||||
case 'submit':
|
||||
$userName = $request->input('username');
|
||||
$password = $request->input('password');
|
||||
$confirmPassword = $request->input('password_confirmation');
|
||||
$email = $request->input('email');
|
||||
$action = $request->input('action') ?? 'view';
|
||||
|
||||
// Get the default user role.
|
||||
$userDefault = Role::query()->where('isdefault', '=', 1)->first();
|
||||
switch ($action) {
|
||||
case 'submit':
|
||||
$userName = $request->input('username');
|
||||
$password = $request->input('password');
|
||||
$confirmPassword = $request->input('password_confirmation');
|
||||
$email = $request->input('email');
|
||||
|
||||
if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE) {
|
||||
if ($inviteCode === '') {
|
||||
$error = 'Sorry, the invite code is old or has been used.';
|
||||
break;
|
||||
}
|
||||
// Get the default user role.
|
||||
$userDefault = Role::query()->where('isdefault', '=', 1)->first();
|
||||
|
||||
$invitedBy = User::checkAndUseInvite($inviteCode);
|
||||
if ($invitedBy < 0) {
|
||||
$error = 'Sorry, the invite code is old or has been used.';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! empty($error)) {
|
||||
return $this->showRegistrationForm($request, $error);
|
||||
}
|
||||
|
||||
if (! empty($error)) {
|
||||
return $this->showRegistrationForm($error);
|
||||
}
|
||||
if( Invite::isAllowed($inviteCode,$email) || Settings::settingValue('..registerstatus') !== Settings::REGISTER_STATUS_INVITE ){
|
||||
|
||||
$user = $this->create(
|
||||
[
|
||||
'username' => $userName,
|
||||
'password' => $password,
|
||||
'email' => $email,
|
||||
'host' => $request->ip(),
|
||||
'roles_id' => $userDefault !== null ? $userDefault['id'] : User::ROLE_USER,
|
||||
'notes' => '',
|
||||
'defaultinvites' => $userDefault !== null ? $userDefault['defaultinvites'] : Invitation::DEFAULT_INVITES,
|
||||
]
|
||||
);
|
||||
$user = $this->create(
|
||||
[
|
||||
'username' => $userName,
|
||||
'password' => $password,
|
||||
'email' => $email,
|
||||
'host' => $request->ip(),
|
||||
'roles_id' => $userDefault !== null ? $userDefault['id'] : User::ROLE_USER,
|
||||
'notes' => '',
|
||||
'defaultinvites' => $userDefault !== null ? $userDefault['defaultinvites'] : Invitation::DEFAULT_INVITES,
|
||||
]
|
||||
);
|
||||
Invite::consume($inviteCode);
|
||||
|
||||
return $this->registered($request, $user) ?: redirect($this->redirectPath());
|
||||
|
||||
break;
|
||||
case 'view': {
|
||||
if ($inviteCode !== null) {
|
||||
// See if it is a valid invite.
|
||||
$invite = Invitation::getInvite($inviteCode);
|
||||
if (! $invite) {
|
||||
$error = sprintf('Bad or invite code older than %d days.', Invitation::DEFAULT_INVITE_EXPIRY_DAYS);
|
||||
$showRegister = 0;
|
||||
} else {
|
||||
$inviteCode = $invite['guid'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'view': {
|
||||
// See if it is a valid invite.
|
||||
if (($inviteCode !== null) && ! Invite::isValid($inviteCode)) {
|
||||
$error = 'Invalid invitation token!';
|
||||
$showRegister = 0;
|
||||
} else {
|
||||
$showRegister = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
app('smarty.view')->assign(
|
||||
@@ -178,29 +168,43 @@ class RegisterController extends Controller
|
||||
'password_confirmation' => Utility::htmlfmt($confirmPassword),
|
||||
'email' => Utility::htmlfmt($email),
|
||||
'invitecode' => Utility::htmlfmt($inviteCode),
|
||||
'invite_code_query' => Utility::htmlfmt($inviteCodeQuery),
|
||||
'showregister' => $showRegister,
|
||||
]
|
||||
);
|
||||
|
||||
return $this->showRegistrationForm($error, $inviteCode);
|
||||
return $this->showRegistrationForm($request, $error, $showRegister);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $error
|
||||
* @param string $inviteCode
|
||||
* @param int $showRegister
|
||||
*/
|
||||
public function showRegistrationForm($error = '', $inviteCode = '')
|
||||
public function showRegistrationForm(Request $request, $error = '', $showRegister = 0)
|
||||
{
|
||||
$showRegister = 1;
|
||||
if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_CLOSED) {
|
||||
$error = 'Registrations are currently disabled.';
|
||||
$showRegister = 0;
|
||||
}
|
||||
if (empty($inviteCode) && ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE)) {
|
||||
$error = 'Registrations are currently invite only.';
|
||||
$inviteCode = '';
|
||||
if ($request->has('invitecode')) {
|
||||
$inviteCode = $request->input('invitecode');
|
||||
}
|
||||
|
||||
if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE) {
|
||||
if (! empty($inviteCode)) {
|
||||
if (Invite::isValid($inviteCode)) {
|
||||
$error = '';
|
||||
$showRegister = 1;
|
||||
} else {
|
||||
$error = 'Invalid or expired invitation token!';
|
||||
$showRegister = 0;
|
||||
}
|
||||
} else {
|
||||
$error = 'Registrations are currently invite only.';
|
||||
$showRegister = 0;
|
||||
}
|
||||
} elseif ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_CLOSED) {
|
||||
$error = 'Registrations are currently closed.';
|
||||
$showRegister = 0;
|
||||
}
|
||||
|
||||
app('smarty.view')->assign('showregister', $showRegister);
|
||||
app('smarty.view')->assign('error', $error);
|
||||
$theme = Settings::settingValue('site.main.style');
|
||||
|
||||
+6
-3
@@ -8,6 +8,8 @@ use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\SendInviteEmail;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Junaidnasir\Larainvite\Facades\Invite;
|
||||
use Junaidnasir\Larainvite\InviteTrait;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Jobs\SendAccountExpiredEmail;
|
||||
@@ -20,6 +22,7 @@ use Jrean\UserVerification\Traits\UserVerification;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
/**
|
||||
* App\Models\User.
|
||||
* App\Models\User.
|
||||
*
|
||||
* @property int $id
|
||||
@@ -116,7 +119,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable, UserVerification, HasRoles;
|
||||
use Notifiable, UserVerification, HasRoles, InviteTrait;
|
||||
|
||||
public const ERR_SIGNUP_BADUNAME = -1;
|
||||
public const ERR_SIGNUP_BADPASS = -2;
|
||||
@@ -880,9 +883,9 @@ class User extends Authenticatable
|
||||
*/
|
||||
public static function sendInvite($serverUrl, $uid, $emailTo): string
|
||||
{
|
||||
$token = \Token::randomString(40);
|
||||
$url = $serverUrl.'/register?invitecode='.$token;
|
||||
$user = self::find($uid);
|
||||
$token = Invite::invite($emailTo, $user->id);
|
||||
$url = $serverUrl.'/register?invitecode='.$token;
|
||||
|
||||
Invitation::addInvite($uid, $token);
|
||||
SendInviteEmail::dispatch($emailTo, $user, $url)->onQueue('emails');
|
||||
|
||||
@@ -41,7 +41,7 @@ class UserServiceObserver
|
||||
SendWelcomeEmail::dispatch($user)->onQueue('welcomeemails');
|
||||
UserVerification::generate($user);
|
||||
|
||||
UserVerification::send($user, 'User email verification required');
|
||||
UserVerification::send($user, 'User email verification required', Settings::settingValue('site.main.email'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
"james-heinrich/getid3": "1.9.*",
|
||||
"joshpinkney/tv-maze-php-api": "dev-master",
|
||||
"jrean/laravel-user-verification": "^7.0",
|
||||
"junaidnasir/larainvite": "^2.0",
|
||||
"kevinlebrun/colors.php": "^1.0",
|
||||
"laravel/framework": "5.8.*",
|
||||
"laravel/horizon": "^3.0",
|
||||
|
||||
Generated
+59
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "344580b9adfd4f74a476559fa23a6823",
|
||||
"content-hash": "0bd9521e4ebcd3b3d9969024ea5941f7",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aharen/omdbapi",
|
||||
@@ -2474,6 +2474,64 @@
|
||||
],
|
||||
"time": "2019-03-01T04:24:17+00:00"
|
||||
},
|
||||
{
|
||||
"name": "junaidnasir/larainvite",
|
||||
"version": "v2.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/junaidnasir/larainvite.git",
|
||||
"reference": "6d079f6cc598bd2057e8c5974f8026b622fa6329"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/junaidnasir/larainvite/zipball/6d079f6cc598bd2057e8c5974f8026b622fa6329",
|
||||
"reference": "6d079f6cc598bd2057e8c5974f8026b622fa6329",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/database": "^5.1",
|
||||
"illuminate/events": "^5.1",
|
||||
"illuminate/support": "^5.1",
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.2"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Junaidnasir\\Larainvite\\LaraInviteServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Invite": "Junaidnasir\\Larainvite\\Facades\\Invite"
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Junaidnasir\\Larainvite\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Junaid Nasir",
|
||||
"email": "contact@junaidnasir.com"
|
||||
}
|
||||
],
|
||||
"description": "Laravel Invitation package, existing users can invite others by email",
|
||||
"homepage": "https://github.com/junaidnasir/larainvite",
|
||||
"keywords": [
|
||||
"Invite",
|
||||
"invitations",
|
||||
"laravel"
|
||||
],
|
||||
"time": "2019-04-24T11:57:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kevinlebrun/colors.php",
|
||||
"version": "1.0.3",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Invitation Expiration Default
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Default Expiry time in Hours from current time.
|
||||
| i.e now() + expires (hours)
|
||||
|
|
||||
*/
|
||||
'expires' => 48,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Model
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'UserModel' => 'App\Models\User',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Invitation Model
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'InvitationModel' => 'Junaidnasir\Larainvite\Models\LaraInviteModel'
|
||||
];
|
||||
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
<div class="register-box-body">
|
||||
<p class="login-box-msg">Register a new membership</p>
|
||||
{{Form::open(['url' => "register?action=submit{$invite_code_query}"])}}
|
||||
{{Form::open(['url' => "register?action=submit"])}}
|
||||
<div class="form-group has-feedback">
|
||||
<input autocomplete="off" id="username" name="username" value="{$username}" type="text"
|
||||
class="form-control" placeholder="Username"/>
|
||||
@@ -52,8 +52,7 @@
|
||||
</div>
|
||||
</div><!-- /.col -->
|
||||
<div class="col-4">
|
||||
<button type="submit" value="Register" class="btn btn-success btn-block btn-flat">Register
|
||||
</button>
|
||||
{{Form::submit('Register', ['class' => "btn btn-success btn-block btn-flat"])}}
|
||||
</div><!-- /.col -->
|
||||
<hr>
|
||||
<div style="text-align: center;">
|
||||
|
||||
+1
-3
@@ -16,9 +16,7 @@ Auth::routes();
|
||||
Route::group(['middleware' => ['fw-block-blacklisted']], function () {
|
||||
Route::get('/', 'ContentController@show');
|
||||
|
||||
Route::get('register', 'Auth\RegisterController@showRegistrationForm');
|
||||
Route::post('register', 'Auth\RegisterController@showRegistrationForm');
|
||||
Route::get('register', 'Auth\RegisterController@register');
|
||||
Route::get('register', 'Auth\RegisterController@showregistrationForm');
|
||||
Route::post('register', 'Auth\RegisterController@register');
|
||||
|
||||
Route::get('forgottenpassword', 'Auth\ForgotPasswordController@showLinkRequestForm');
|
||||
|
||||
Reference in New Issue
Block a user