Skip to content

Commit

Permalink
update logics
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshadhin committed May 18, 2018
1 parent 3b05cca commit 93c2642
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 307 deletions.
18 changes: 18 additions & 0 deletions app/composers/ComposerServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SMS\Composers;

use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider
{

public function register()
{
$this->app->view->composer(
"layouts.master",
"SMS\Composers\MasterComposer"
);
}

}
20 changes: 20 additions & 0 deletions app/composers/MasterComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* attached variable to the master view
*/
namespace SMS\Composers;

use Illuminate\View\View;

class MasterComposer
{
/**
* compose the view with related variable
*/

public function compose(View $view)
{
$view->with('idc', 'a2912335b89e3cf6ea0034d0abf74f870d2c769f');
}

}
7 changes: 5 additions & 2 deletions app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
'Maatwebsite\Excel\ExcelServiceProvider',
'Barryvdh\DomPDF\ServiceProvider',
'Davelip\Queue\DatabaseServiceProvider',
'SMS\Composers\ComposerServiceProvider',

),

Expand Down Expand Up @@ -192,8 +193,10 @@
'URL' => 'Illuminate\Support\Facades\URL',
'Validator' => 'Illuminate\Support\Facades\Validator',
'View' => 'Illuminate\Support\Facades\View',
'Excel' => 'Maatwebsite\Excel\Facades\Excel',
'PDF' => 'Barryvdh\DomPDF\Facade'
'Excel' => 'Maatwebsite\Excel\Facades\Excel',
'PDF' => 'Barryvdh\DomPDF\Facade',
'SmsHelper' => 'App\Helpers\AppHelper::class',


),

Expand Down
312 changes: 161 additions & 151 deletions app/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,173 +3,183 @@

use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
class UsersController extends \BaseController {
public function __construct() {
$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('show','create','edit','update')));
$this->beforeFilter('userAccess',array('only'=> array('show','create','edit','update','delete')));
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function postSignin() {
if (\Auth::attempt(array('login'=>Input::get('login'), 'password'=>Input::get('password')))) {
$name=Auth::user()->firstname.' '.Auth::user()->lastname;
Session::put('name', $name);
$institute=Institute::select('name')->first();
if(!$institute)
{
if (Auth::user()->group != "Admin")
{
return Redirect::to('/')
->withInput(Input::all())->with('error', 'Institute Information not setup yet!Please contact administrator.');
}
else {
$institute=new Institute;
$institute->name="ShanixLab";
Session::put('inName', $institute->name);
return Redirect::to('/institute')->with('error','Please provide institute information!');
use App\Helpers\AppHelper;



class UsersController extends \BaseController
{
public function __construct()
{
$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('show','create','edit','update')));
$this->beforeFilter('userAccess', array('only'=> array('show','create','edit','update','delete')));
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function postSignin()
{
if (\Auth::attempt(array('login'=>Input::get('login'), 'password'=>Input::get('password')))) {
$name=Auth::user()->firstname.' '.Auth::user()->lastname;
Session::put('name', $name);

Session::put('user_session_sha1', AppHelper::getUserSessionHash());


$institute=Institute::select('name')->first();

if(!$institute) {
if (Auth::user()->group != "Admin") {
return Redirect::to('/')
->withInput(Input::all())->with('error', 'Institute Information not setup yet!Please contact administrator.');
}
else {
$institute=new Institute;
$institute->name="ShanixLab";
Session::put('inName', $institute->name);
return Redirect::to('/institute')->with('error', 'Please provide institute information!');

}
}
else {
Session::put('inName', $institute->name);
Session::put('inNameShort', AppHelper::getShortName($institute->name));
return Redirect::to('/dashboard')->with('success', 'You are now logged in.');
}

} else {
return Redirect::to('/')
->withInput(Input::all())->with('error', 'Your username/password combination was incorrect');

}
}
else {
Session::put('inName', $institute->name);
return Redirect::to('/dashboard')->with('success','You are now logged in.');
}

} else {
return Redirect::to('/')
->withInput(Input::all())->with('error', 'Your username/password combination was incorrect');
}



public function getLogout()
{
Session::flush();
\Auth::logout();
return Redirect::to('/')->with('message', 'Your are now logged out!');
}

}



public function getLogout() {
\Auth::logout();
return Redirect::to('/')->with('message', 'Your are now logged out!');
}

public function show()
{
$users= User::all();
$user=array();
return View::Make('app.users',compact('users','user'));
}
public function create()
{
$rules=[
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'group' => 'required',
'desc' => 'required',
'login' => 'required',
'password' => 'required'

];
$validator = \Validator::make(Input::all(), $rules);
if ($validator->fails())
public function show()
{
return Redirect::to('/users')->withInput(Input::all())->withErrors($validator);
$users= User::all();
$user=array();
return View::Make('app.users', compact('users', 'user'));
}
else {

$uexits = User::select('*')->where('email','=',Input::get('email'))->orwhere('login','=',Input::get('login'))->get();
if(count($uexits)>0)
{
$errorMessages = new Illuminate\Support\MessageBag;
$errorMessages->add('deplicate', 'User all ready exists with this email or login');
return Redirect::to('/users')->withInput(Input::all())->withErrors($errorMessages);

}
{
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->login = Input::get('login');
$user->desc = Input::get('desc');
$user->email = Input::get('email');
$user->group = Input::get('group');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users')->with("success","User Created Succesfully.");
}
public function create()
{
$rules=[
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'group' => 'required',
'desc' => 'required',
'login' => 'required',
'password' => 'required'

];
$validator = \Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/users')->withInput(Input::all())->withErrors($validator);
}
else {

$uexits = User::select('*')->where('email', '=', Input::get('email'))->orwhere('login', '=', Input::get('login'))->get();
if(count($uexits)>0) {
$errorMessages = new Illuminate\Support\MessageBag;
$errorMessages->add('deplicate', 'User all ready exists with this email or login');
return Redirect::to('/users')->withInput(Input::all())->withErrors($errorMessages);

}
{
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->login = Input::get('login');
$user->desc = Input::get('desc');
$user->email = Input::get('email');
$user->group = Input::get('group');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users')->with("success", "User Created Succesfully.");
}


}
}
}
public function edit($id)
{
$user = User::find($id);
$users= User::all();
return View::Make('app.users',compact('users','user'));

}
public function update()
{
$rules=[
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'group' => 'required',
'desc' => 'required',
'login' => 'required',
'password' => 'required'

];
$validator = \Validator::make(Input::all(), $rules);
if ($validator->fails())
public function edit($id)
{
return Redirect::to('/usersedit/'.Input::get('id'))->withErrors($validator);
$user = User::find($id);
$users= User::all();
return View::Make('app.users', compact('users', 'user'));

}
else {

$uexits = User::select('*')->where('email','=',Input::get('email'))->first();
if(count($uexits)>0) {
if ($uexits->id != Input::get('id')) {
$errorMessages = new Illuminate\Support\MessageBag;
$errorMessages->add('deplicate', 'User all ready exists with this email');
return Redirect::to('/users')->withInput(Input::all())->withErrors($errorMessages);
} else {
$user = User::find(Input::get('id'));
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
// $user->login = Input::get('login');
$user->desc = Input::get('desc');
$user->email = Input::get('email');
$user->group = Input::get('group');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users')->with("success", "User Updated Succesfully.");
public function update()
{
$rules=[
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'group' => 'required',
'desc' => 'required',
'login' => 'required',
'password' => 'required'

];
$validator = \Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/usersedit/'.Input::get('id'))->withErrors($validator);
}
}
else
{
$user = User::find(Input::get('id'));
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
// $user->login = Input::get('login');
$user->desc = Input::get('desc');
$user->email = Input::get('email');
$user->group = Input::get('group');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users')->with("success", "User Updated Succesfully.");
}
else {

$uexits = User::select('*')->where('email', '=', Input::get('email'))->first();
if(count($uexits)>0) {
if ($uexits->id != Input::get('id')) {
$errorMessages = new Illuminate\Support\MessageBag;
$errorMessages->add('deplicate', 'User all ready exists with this email');
return Redirect::to('/users')->withInput(Input::all())->withErrors($errorMessages);
} else {
$user = User::find(Input::get('id'));
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
// $user->login = Input::get('login');
$user->desc = Input::get('desc');
$user->email = Input::get('email');
$user->group = Input::get('group');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users')->with("success", "User Updated Succesfully.");
}
}
else
{
$user = User::find(Input::get('id'));
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
// $user->login = Input::get('login');
$user->desc = Input::get('desc');
$user->email = Input::get('email');
$user->group = Input::get('group');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users')->with("success", "User Updated Succesfully.");
}

}
}
}

public function delete($id)
{
$user= User::find($id);
$user->delete();
return Redirect::to('/users')->with("success","User Deleted Succesfully.");
public function delete($id)
{
$user= User::find($id);
$user->delete();
return Redirect::to('/users')->with("success", "User Deleted Succesfully.");

}
}
}
Loading

0 comments on commit 93c2642

Please sign in to comment.