Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
24a3605a
Commit
24a3605a
authored
Dec 24, 2017
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Make created_by null on user table through migration
- User Registration Class
parent
1b0f7adc
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
168 additions
and
6 deletions
+168
-6
.env.example
.env.example
+4
-0
RegisterController.php
app/Http/Controllers/Frontend/Auth/RegisterController.php
+17
-1
UserEventListener.php
app/Listeners/Frontend/Auth/UserEventListener.php
+9
-1
UserRepository.php
app/Repositories/Frontend/Access/User/UserRepository.php
+20
-1
access.php
config/access.php
+7
-1
2017_12_24_042039_add_null_constraint_on_created_by_on_user_table.php
...42039_add_null_constraint_on_created_by_on_user_table.php
+30
-0
UserTableSeeder.php
database/seeds/Access/UserTableSeeder.php
+2
-2
RegistrationTest.php
tests/Feature/RegistrationTest.php
+79
-0
No files found.
.env.example
View file @
24a3605a
...
...
@@ -12,6 +12,10 @@ DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
# Access
ENABLE_REGISTRATION=true
REQUIRES_APPROVAL=false
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
...
...
app/Http/Controllers/Frontend/Auth/RegisterController.php
View file @
24a3605a
...
...
@@ -50,7 +50,7 @@ class RegisterController extends Controller
*/
public
function
register
(
RegisterRequest
$request
)
{
if
(
config
(
'access.users.confirm_email'
))
{
/*
if (config('access.users.confirm_email')) {
$user = $this->user->create($request->all());
event(new UserRegistered($user));
...
...
@@ -59,6 +59,22 @@ class RegisterController extends Controller
access()->login($this->user->create($request->all()));
event(new UserRegistered(access()->user()));
return redirect($this->redirectPath());
}*/
if
(
config
(
'access.users.confirm_email'
)
||
config
(
'access.users.requires_approval'
))
{
$user
=
$this
->
user
->
create
(
$request
->
only
(
'first_name'
,
'last_name'
,
'email'
,
'password'
,
'is_term_accept'
));
event
(
new
UserRegistered
(
$user
));
return
redirect
(
$this
->
redirectPath
())
->
withFlashSuccess
(
config
(
'access.users.requires_approval'
)
?
trans
(
'exceptions.frontend.auth.confirmation.created_pending'
)
:
trans
(
'exceptions.frontend.auth.confirmation.created_confirm'
)
);
}
else
{
access
()
->
login
(
$this
->
user
->
create
(
$request
->
only
(
'first_name'
,
'last_name'
,
'email'
,
'password'
,
'is_term_accept'
)));
event
(
new
UserRegistered
(
access
()
->
user
()));
return
redirect
(
$this
->
redirectPath
());
}
}
...
...
app/Listeners/Frontend/Auth/UserEventListener.php
View file @
24a3605a
...
...
@@ -30,6 +30,14 @@ class UserEventListener
* @param $event
*/
public
function
onRegistered
(
$event
)
{
\Log
::
info
(
'User Registered: '
.
$event
->
user
->
full_name
);
}
/**
* @param $event
*/
/*public function onRegistered($event)
{
\Log::info('User Registered: '.$event->user->first_name);
...
...
@@ -39,7 +47,7 @@ class UserEventListener
'email_template_type' => 1,
];
createNotification('', 1, 2, $options);
}
}
*/
/**
* @param $event
...
...
app/Repositories/Frontend/Access/User/UserRepository.php
View file @
24a3605a
...
...
@@ -79,6 +79,8 @@ class UserRepository extends BaseRepository
}
/**
* Create User
*
* @param array $data
* @param bool $provider
*
...
...
@@ -94,9 +96,26 @@ class UserRepository extends BaseRepository
$user
->
confirmation_code
=
md5
(
uniqid
(
mt_rand
(),
true
));
$user
->
status
=
1
;
$user
->
password
=
$provider
?
null
:
bcrypt
(
$data
[
'password'
]);
$user
->
confirmed
=
$provider
?
1
:
(
config
(
'access.users.confirm_email'
)
?
0
:
1
);
$user
->
is_term_accept
=
$data
[
'is_term_accept'
];
// If users require approval, confirmed is false regardless of account type
if
(
config
(
'access.users.requires_approval'
))
{
$user
->
confirmed
=
0
;
// No confirm e-mail sent, that defeats the purpose of manual approval
}
elseif
(
config
(
'access.users.confirm_email'
))
{
// If user must confirm email
// If user is from social, already confirmed
if
(
$provider
)
{
$user
->
confirmed
=
1
;
// E-mails are validated through the social platform
}
else
{
// Otherwise needs confirmation
$user
->
confirmed
=
0
;
$confirm
=
true
;
}
}
else
{
// Otherwise both are off and confirmed is default
$user
->
confirmed
=
1
;
}
DB
::
transaction
(
function
()
use
(
$user
)
{
if
(
$user
->
save
())
{
/*
...
...
config/access.php
View file @
24a3605a
...
...
@@ -88,7 +88,7 @@ return [
/*
* Whether or not public registration is on
*/
'registration'
=>
env
(
'ENABLE_REGISTRATION'
,
'true'
),
'registration'
=>
env
(
'ENABLE_REGISTRATION'
,
true
),
/*
* The role the user is assigned to when they sign up from the frontend, not namespaced
...
...
@@ -105,6 +105,12 @@ return [
* Whether or not the users email can be changed on the edit profile screen
*/
'change_email'
=>
false
,
/*
* Whether or not new users need to be approved by an administrator before logging in
* If this is set to true, then confirm_email is not in effect
*/
'requires_approval'
=>
env
(
'REQUIRES_APPROVAL'
,
false
),
],
/*
...
...
database/migrations/2017_12_24_042039_add_null_constraint_on_created_by_on_user_table.php
0 → 100644
View file @
24a3605a
<?php
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
AddNullConstraintOnCreatedByOnUserTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'users'
,
function
(
Blueprint
$table
)
{
$table
->
integer
(
'created_by'
)
->
nullable
()
->
change
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
//
}
}
database/seeds/Access/UserTableSeeder.php
View file @
24a3605a
...
...
@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder
'deleted_at'
=>
null
,
],
[
'first_name'
=>
'
John
'
,
'last_name'
=>
'
Doe
'
,
'first_name'
=>
'
User
'
,
'last_name'
=>
'
Test
'
,
'email'
=>
'user@user.com'
,
'password'
=>
bcrypt
(
'1234'
),
'confirmation_code'
=>
md5
(
uniqid
(
mt_rand
(),
true
)),
...
...
tests/Feature/RegistrationTest.php
0 → 100644
View file @
24a3605a
<?php
namespace
Tests\Feature
;
use
Faker\Generator
;
use
Tests\BrowserKitTestCase
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\Event
;
use
App\Events\Frontend\Auth\UserLoggedIn
;
use
App\Events\Frontend\Auth\UserRegistered
;
class
RegistrationTest
extends
BrowserKitTestCase
{
/** @test */
public
function
registration_page_loads_properly
()
{
$this
->
visit
(
'/register'
)
->
see
(
'first_name'
)
->
see
(
'last_name'
)
->
see
(
'email'
)
->
see
(
'password'
)
->
see
(
'is_term_accept'
)
->
see
(
'Register'
);
}
/** @test */
public
function
registration_fails_when_a_required_field_is_not_filled_in
()
{
$this
->
visit
(
'/register'
)
->
type
(
''
,
'first_name'
)
->
type
(
''
,
'last_name'
)
->
type
(
''
,
'email'
)
->
type
(
''
,
'password'
)
->
press
(
'Register'
)
->
seePageIs
(
'/register'
)
->
see
(
'The first name field is required.'
)
->
see
(
'The last name field is required.'
)
->
see
(
'The email field is required.'
)
->
see
(
'The password field is required.'
)
->
see
(
'The is term accept field is required.'
);
}
/**
* Test the registration form
* Test it works with confirming email on or off, and that the confirm email notification is sent
* Note: Captcha is disabled by default in phpunit.xml.
*/
/** @test */
public
function
test_registration_form
()
{
// Make sure our events are fired
Event
::
fake
();
config
([
'access.users.confirm_email'
=>
false
]);
config
([
'access.users.requires_approval'
=>
false
]);
$this
->
visit
(
'/register'
)
->
type
(
'John'
,
'first_name'
)
->
type
(
'Doe'
,
'last_name'
)
->
type
(
'john.doe@example.com'
,
'email'
)
->
type
(
'Viral@1234'
,
'password'
)
->
type
(
'Viral@1234'
,
'password_confirmation'
)
->
check
(
'is_term_accept'
)
->
press
(
'Register'
)
->
seePageIs
(
'/'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'email'
=>
'john.doe@example.com'
,
'first_name'
=>
'John'
,
'last_name'
=>
'Doe'
,
'confirmed'
=>
1
,
]);
Event
::
assertDispatched
(
UserRegistered
::
class
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment