-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * Layout Changes * wip * wip * wip * wip
- Loading branch information
Jovert Lota Palonpon
authored
Apr 20, 2019
1 parent
f55cba1
commit fb2c5c1
Showing
29 changed files
with
2,177 additions
and
341 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
app/Http/Controllers/Api/V1/Settings/AccountController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1\Settings; | ||
|
||
use Hash; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Validation\ValidationException; | ||
|
||
class AccountController extends Controller | ||
{ | ||
/** | ||
* @var App\User | ||
*/ | ||
protected $user; | ||
|
||
/** | ||
* Create a new AccountController | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->user = auth()->guard('api')->user(); | ||
} | ||
|
||
/** | ||
* Update User's login credentials | ||
* | ||
* @param Illuminate\Http\Request $request | ||
* | ||
* @return Illuminate\Http\JsonResponse | ||
*/ | ||
public function updateCredentials(Request $request) : JsonResponse | ||
{ | ||
$request->validate([ | ||
'username' => | ||
"required|string|unique:users,username,{$this->user->id},id,deleted_at,NULL", | ||
'email' => | ||
"required|email|unique:users,email,{$this->user->id},id,deleted_at,NULL" | ||
]); | ||
|
||
$this->user->username = $request->input('username'); | ||
$this->user->email = $request->input('email'); | ||
$this->user->update(); | ||
|
||
return response()->json($this->user); | ||
} | ||
|
||
/** | ||
* Update User's password | ||
* | ||
* @param Illuminate\Http\Request $request | ||
* | ||
* @return Illuminate\Http\JsonResponse | ||
*/ | ||
public function updatePassword(Request $request) : JsonResponse | ||
{ | ||
$request->validate([ | ||
'old_password' => 'required|string', | ||
'password' => 'required|string|confirmed|min:8|pwned:100' | ||
]); | ||
|
||
if (! Hash::check($request->input('old_password'), $this->user->password)) { | ||
throw ValidationException::withMessages([ | ||
'old_password' => [trans('auth.password_mismatch')] | ||
]); | ||
|
||
return response()->json('Password was not Changed!', 422); | ||
} | ||
|
||
$this->user->password = bcrypt($request->input('password')); | ||
$this->user->update(); | ||
|
||
return response()->json('Password Changed!'); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/Http/Controllers/Api/V1/Settings/ProfileController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1\Settings; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\Controller; | ||
|
||
class ProfileController extends Controller | ||
{ | ||
/** | ||
* Update User's profile | ||
* | ||
* @param Illuminate\Http\Request $request | ||
* | ||
* @return Illuminate\Http\JsonResponse | ||
*/ | ||
public function update(Request $request) : JsonResponse | ||
{ | ||
$user = auth()->guard('api')->user(); | ||
|
||
$request->validate([ | ||
'firstname' => 'required|string|max:255', | ||
'lastname' => 'required|string|max:255', | ||
|
||
'gender' => 'nullable|in:female,male', | ||
'birthdate' => | ||
'nullable|date:Y-m-d|before:'.now()->subYear(10)->format('Y-m-d'), | ||
'address' => 'nullable|string|max:510', | ||
]); | ||
|
||
$attributes = $request->all(); | ||
unset($attributes['auth_token']); | ||
|
||
$user->fill($attributes); | ||
$user->update(); | ||
|
||
return response()->json($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
CircularProgress, | ||
CssBaseline, | ||
Grid, | ||
Hidden, | ||
withStyles, | ||
} from '@material-ui/core'; | ||
import classNames from 'classnames'; | ||
|
||
import { Snackbar } from '../../../ui'; | ||
import { LinearDeterminate } from '../../../ui/Loaders'; | ||
import { Footer, Header, Sidebar } from '../partials'; | ||
|
||
function Clean(props) { | ||
const { classes, ...other } = props; | ||
const { history, loading, message } = props; | ||
|
||
const [drawerOpen, setDrawer] = useState(false); | ||
const [localeMenuOpen, setLocaleMenu] = useState(false); | ||
const [accountMenuOpen, setAccountMenu] = useState(false); | ||
|
||
const sidebarProps = Object.assign(other, { | ||
navigate: path => history.push(path), | ||
PaperProps: { style: { width: drawerWidth } }, | ||
open: drawerOpen, | ||
onClose: () => setDrawer(!drawerOpen), | ||
}); | ||
|
||
const renderLoading = ( | ||
<Grid | ||
container | ||
className={classes.root} | ||
justify="center" | ||
alignItems="center" | ||
> | ||
<Grid item> | ||
<CircularProgress color="primary" /> | ||
</Grid> | ||
</Grid> | ||
); | ||
|
||
return ( | ||
<> | ||
{loading && <LinearDeterminate className={classes.loader} />} | ||
|
||
<div className={classes.root}> | ||
<CssBaseline /> | ||
|
||
<nav className={classes.drawer}> | ||
<Hidden smUp implementation="js"> | ||
<Sidebar {...sidebarProps} variant="temporary" /> | ||
</Hidden> | ||
|
||
<Hidden xsDown implementation="css"> | ||
<Sidebar {...sidebarProps} variant="persistent" /> | ||
</Hidden> | ||
</nav> | ||
|
||
<div className={classes.contentWrapper}> | ||
<Header | ||
{...other} | ||
variant="slim" | ||
drawerOpen={drawerOpen} | ||
accountMenuOpen={accountMenuOpen} | ||
localeMenuOpen={localeMenuOpen} | ||
onDrawerToggle={() => setDrawer(!drawerOpen)} | ||
onLocaleMenuToggle={() => | ||
setLocaleMenu(!localeMenuOpen) | ||
} | ||
onAccountMenuToggle={() => | ||
setAccountMenu(!accountMenuOpen) | ||
} | ||
/> | ||
|
||
<main | ||
className={classNames(classes.content, { | ||
[classes.contentShift]: drawerOpen, | ||
})} | ||
> | ||
{loading ? renderLoading : props.children} | ||
</main> | ||
</div> | ||
|
||
<Footer /> | ||
</div> | ||
|
||
{message && message.hasOwnProperty('type') && ( | ||
<Snackbar {...message} /> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
Clean.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
history: PropTypes.object.isRequired, | ||
location: PropTypes.object.isRequired, | ||
match: PropTypes.object.isRequired, | ||
pageProps: PropTypes.object.isRequired, | ||
|
||
pageTitle: PropTypes.string, | ||
loading: PropTypes.bool, | ||
message: PropTypes.object, | ||
}; | ||
|
||
Clean.defaultProps = { | ||
pageTitle: '', | ||
loading: false, | ||
message: {}, | ||
}; | ||
|
||
const drawerWidth = 256; | ||
|
||
const styles = theme => ({ | ||
loader: { | ||
zIndex: 9999, | ||
}, | ||
|
||
root: { | ||
display: 'flex', | ||
position: 'relative', | ||
minHeight: '100vh', | ||
maxWidth: '100%', | ||
}, | ||
|
||
drawer: { | ||
drawer: { | ||
width: drawerWidth, | ||
flexShrink: 0, | ||
}, | ||
}, | ||
|
||
contentWrapper: { | ||
flex: 1, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
overflowX: 'scroll', | ||
}, | ||
|
||
content: { | ||
flex: 1, | ||
padding: `0 ${theme.spacing.unit}px`, | ||
marginBottom: 75, | ||
marginLeft: 0, | ||
[theme.breakpoints.up('sm')]: { | ||
marginBottom: 50, | ||
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`, | ||
}, | ||
}, | ||
|
||
contentShift: { | ||
[theme.breakpoints.up('sm')]: { | ||
transition: theme.transitions.create('margin', { | ||
easing: theme.transitions.easing.easeOut, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
marginLeft: drawerWidth, | ||
}, | ||
}, | ||
}); | ||
|
||
export default withStyles(styles)(Clean); |
Oops, something went wrong.