Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-12-14 20:13:32 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
93223fcd3d08b3255566ca6a7626d3e6cf3a25e9
93223fcd
1 parent
8f7c642f
Cleaned up gravatar image importing
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
15 deletions
app/Http/Controllers/UserController.php
app/Image.php
app/Services/ImageService.php
app/User.php
phpunit.xml
app/Http/Controllers/UserController.php
View file @
93223fc
...
...
@@ -4,7 +4,7 @@ namespace BookStack\Http\Controllers;
use
Illuminate\Http\Request
;
use
Illuminate\
Support\Facades\Hash
;
use
Illuminate\
Http\Response
;
use
BookStack\Http\Requests
;
use
BookStack\Repos\UserRepo
;
use
BookStack\Services\SocialAuthService
;
...
...
@@ -30,7 +30,6 @@ class UserController extends Controller
/**
* Display a listing of the users.
*
* @return Response
*/
public
function
index
()
...
...
@@ -42,7 +41,6 @@ class UserController extends Controller
/**
* Show the form for creating a new user.
*
* @return Response
*/
public
function
create
()
...
...
@@ -53,7 +51,6 @@ class UserController extends Controller
/**
* Store a newly created user in storage.
*
* @param Request $request
* @return Response
*/
...
...
@@ -73,13 +70,20 @@ class UserController extends Controller
$user
->
save
();
$user
->
attachRoleId
(
$request
->
get
(
'role'
));
// Get avatar from gravatar and save
if
(
!
env
(
'DISABLE_EXTERNAL_SERVICES'
,
false
))
{
$avatar
=
\Images
::
saveUserGravatar
(
$user
);
$user
->
avatar
()
->
associate
(
$avatar
);
$user
->
save
();
}
return
redirect
(
'/users'
);
}
/**
* Show the form for editing the specified user.
*
* @param int $id
* @param SocialAuthService $socialAuthService
* @return Response
...
...
@@ -98,7 +102,6 @@ class UserController extends Controller
/**
* Update the specified user in storage.
*
* @param Request $request
* @param int $id
* @return Response
...
...
@@ -148,7 +151,6 @@ class UserController extends Controller
/**
* Remove the specified user from storage.
*
* @param int $id
* @return Response
*/
...
...
@@ -158,11 +160,13 @@ class UserController extends Controller
return
$this
->
currentUser
->
id
==
$id
;
});
$user
=
$this
->
userRepo
->
getById
(
$id
);
// Delete social accounts
if
(
$this
->
userRepo
->
isOnlyAdmin
(
$user
))
{
if
(
$this
->
userRepo
->
isOnlyAdmin
(
$user
))
{
session
()
->
flash
(
'error'
,
'You cannot delete the only admin'
);
return
redirect
(
$user
->
getEditUrl
());
}
$user
->
socialAccounts
()
->
delete
();
$user
->
delete
();
return
redirect
(
'/users'
);
...
...
app/Image.php
View file @
93223fc
...
...
@@ -16,11 +16,11 @@ class Image extends Model
* Get a thumbnail for this image.
* @param int $width
* @param int $height
* @param bool|false $
hardCrop
* @param bool|false $
keepRatio
* @return string
*/
public
function
getThumb
(
$width
,
$height
,
$
hardCrop
=
false
)
public
function
getThumb
(
$width
,
$height
,
$
keepRatio
=
false
)
{
return
Images
::
getThumbnail
(
$this
,
$width
,
$height
,
$
hardCrop
);
return
Images
::
getThumbnail
(
$this
,
$width
,
$height
,
$
keepRatio
);
}
}
...
...
app/Services/ImageService.php
View file @
93223fc
...
...
@@ -183,15 +183,12 @@ class ImageService
*/
public
function
saveUserGravatar
(
User
$user
,
$size
=
500
)
{
if
(
!
env
(
'USE_GRAVATAR'
,
false
))
return
false
;
$emailHash
=
md5
(
strtolower
(
trim
(
$user
->
email
)));
$url
=
'http://www.gravatar.com/avatar/'
.
$emailHash
.
'?s='
.
$size
.
'&d=identicon'
;
$imageName
=
str_replace
(
' '
,
'-'
,
$user
->
name
.
'-gravatar.png'
);
$image
=
$this
->
saveNewFromUrl
(
$url
,
'user'
,
$imageName
);
$image
->
created_by
=
$user
->
id
;
$image
->
save
();
$user
->
avatar
()
->
associate
(
$image
);
$user
->
save
();
return
$image
;
}
...
...
app/User.php
View file @
93223fc
...
...
@@ -146,7 +146,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
public
function
getAvatar
(
$size
=
50
)
{
if
(
$this
->
image_id
===
0
||
$this
->
image_id
===
null
)
return
'/user_avatar.png'
;
return
$this
->
avatar
->
getThumb
(
$size
,
$size
,
tru
e
);
return
$this
->
avatar
->
getThumb
(
$size
,
$size
,
fals
e
);
}
/**
...
...
phpunit.xml
View file @
93223fc
...
...
@@ -26,5 +26,6 @@
<env
name=
"QUEUE_DRIVER"
value=
"sync"
/>
<env
name=
"DB_CONNECTION"
value=
"mysql_testing"
/>
<env
name=
"MAIL_PRETEND"
value=
"true"
/>
<env
name=
"DISABLE_EXTERNAL_SERVICES"
value=
"true"
/>
</php>
</phpunit>
...
...
Please
register
or
sign in
to post a comment