Skip to content

Commit

Permalink
updated version with database initial set up
Browse files Browse the repository at this point in the history
  • Loading branch information
Chithra-J committed May 1, 2016
1 parent 0c0f9cb commit 87d064a
Show file tree
Hide file tree
Showing 52 changed files with 5,355 additions and 564 deletions.
14 changes: 14 additions & 0 deletions app/Children.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace P4;

use Illuminate\Database\Eloquent\Model;

class Children extends Model
{
public function user_parent() {
# Child has one parent
# Define a one-to-many relationship.
return $this->belongsTo('\P4\UserParent');
}
}
111 changes: 65 additions & 46 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,84 @@
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
class AuthController extends Controller {
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers, ThrottlesLogins;
use AuthenticatesAndRegistersUsers, ThrottlesLogins;

/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
# Where should the user be redirected to if their login fails?
protected $loginPath = '/login';

/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
# Where should the user be redirected to after logging out?
protected $redirectAfterLogout = '/';

/**
* Get a validator for an incoming registration request.
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';

/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct() {
$this -> middleware($this -> guestMiddleware(), ['except' => 'logout']);
}

/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data) {
return Validator::make($data, ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed', ]);
}

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
* @return User
*/
protected function validator(array $data)
protected function create(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'middle' => $data['middle'],
'lastname' => $data['lastname'],
'firstname' => $data['firstname'],
'gender' => (((array_key_exists('female',$data)) && !is_null($data['female']) && ($data['female'] == "on")) ?
"female" : (((array_key_exists('male',$data)) &&!is_null($data['male']) && ($data['male'] == "on")) ? "male" : "")),
]);
}

/**
* Create a new user instance after a valid registration.
* Log the user out of the application.
*
* @param array $data
* @return User
* @return \Illuminate\Http\Response
*/
protected function create(array $data)
public function logout()
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
\Auth::guard($this->getGuard())->logout();

\Session::flash('message','You have been logged out.');

return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}

}
53 changes: 53 additions & 0 deletions app/Http/Controllers/ChildrenController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace P4\Http\Controllers;
require __DIR__ . '/../../../vendor/autoload.php';
use P4\Http\Controllers\Controller;
use Illuminate\Http\Request;
use P4\Http\Requests;
use Auth;

class ChildrenController extends Controller {
public function getCreate() {
$parent = \P4\User::where('email', '=', Auth::user() -> email) -> get() -> first();
/*
$parent = \P4\Children::find(Auth::user() -> id);
return view('parents.getparentsdetails') -> with(['parent' => $parent]);*/
return view('children.getchildrendetails') -> with(['parent' => $parent]);
}

public function getExisting(Request $request) {
//$this -> validate($request, ['username' => 'required|string', 'password' => 'required|string', ]);
$data = $request -> all();
$child = \P4\Children::where('user_parent_id', '=', $data['user_parent_id']) -> get() -> first();
if ($parent != null) {
return view('children.showchildrendetails') -> with('child', $child);
} else {
\Session::flash('message', 'No such registered email adress! Please verify your username');
return redirect('/parents/login');
}
}
public function postCreate(Request $request) {

$this -> validate($request, ['firstname' => 'required|string', 'lastname' => 'required|string', 'date_of_birth' => 'required|string', ]);

$data = $request -> all();
/*
$parent = \P4\UserParent::where('username', '=', $data['username']) -> get() -> first();
if ($parent != null) {
\Session::flash('message', 'Username already exist! Please try login using your username');
return redirect('/parents/login');
} else {
// Create new Parent
$parent = new \P4\UserParent();
$parent -> firstname = $data['firstname'];
$parent -> lastname = $data['lastname'];
$parent -> username = $data['username'];
$parent -> save();
}
*/

return view('children.showchildrendetails') -> with(['child' => child]);
}

}
147 changes: 127 additions & 20 deletions app/Http/Controllers/ParentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,156 @@
use P4\Http\Controllers\Controller;
use Illuminate\Http\Request;
use P4\Http\Requests;
//use P4\app\Parent;
use Auth;
use File;

class ParentsController extends Controller {

public function getCreate() {
return view('parents.getparentsdetails');
//$parent = \P4\User::where('email', '=', Auth::user() -> email) -> get() -> first();
$parent = \P4\User::find(Auth::user() -> id);
return view('parents.getparentsdetails') -> with(['parent' => $parent]);
}

public function getLogin() {
return view('parents.getlogindetails');

public function postEdit(Request $request) {

$parent = \P4\User::find($request->user_id);

//$parent = \P4\User::where('email', '=', $request -> email) -> get() -> first();
//dump($parent);
print_r($request);

$parent -> firstname = $request -> firstname;
$parent -> lastname = $request -> lastname;
$parent -> middle = $request -> middle;
$parent -> name = $request -> username;
$parent -> password = \Hash::make($request -> password);
if (!is_null($request -> female) && ($request -> female == "on")) {
$parent -> gender = "female";
}
if (!is_null($request -> male) && ($request -> male == "on")) {
$parent -> gender = "male";
}
//$parent -> gender = $request -> gender;
$parent -> save();

\Session::flash('message', 'Your profile changes were saved.');
return view('parents.showparentsdetails') -> with(['parent' => $parent]);

}

/*
public function getExisting(Request $request) {
$this -> validate($request, ['username' => 'required|string', 'password' => 'required|string', ]);
$data = $request -> all();
$parent = \P4\UserParent::where('username', '=', $data['username']) -> get() -> first();
if ($parent != null) {
return view('parents.showparentsdetails') -> with('parent', $parent);
} else {
\Session::flash('message', 'No such username! Please verify your username');
return redirect('/parents/login');
$this -> validate($request, ['email' => 'required|string', 'password' => 'required|string', ]);
$parent = \P4\User::where('email', '=', $request -> email) -> get() -> first();
if ($parent != null) {
return view('parents.showparentsdetails') -> with('parent', $parent);
} else {
\Session::flash('message', 'No such registered email adress! Please verify your username');
return redirect('/parents/login');
}
}
}
public function postCreate(Request $request) {
$this -> validate($request, ['firstname' => 'required|string', 'email' => 'required|string', 'password' => 'required|string', 'confirm_password' => 'required|string', ]);
$data = $request -> all();
$parent = \P4\UserParent::where('username', '=', $data['username']) -> get() -> first();
//$data = $request -> all();
dump($request);
$parent = \P4\User::where('email', '=', $request -> email) -> get() -> first();
if ($parent != null) {
\Session::flash('message', 'Username already exist! Please try login using your username');
\Session::flash('message', 'You have already signed up to Clap! Please try login using your email address');
return redirect('/parents/login');
} else {
// Create new Parent
$parent = new \P4\UserParent();
$parent -> firstname = $data['firstname'];
$parent -> lastname = $data['lastname'];
$parent -> username = $data['username'];
$parent = new \P4\User();
$parent -> firstname = $request -> firstname;
$parent -> lastname = $request -> lastname;
$parent -> middle = $request -> middle;
$parent -> name = $request -> username;
$parent -> password = \Hash::make($request -> password);
//$parent->picture_location = $request->picture_location;
if (!is_null($request -> female) && ($request -> female == "on")) {
$parent -> gender = "female";
}
if (!is_null($request -> male) && ($request -> male == "on")) {
$parent -> gender = "male";
}
$parent -> save();
dump($parent);
}
return view('parents.showparentsdetails') -> with(['parent' => $parent]);
}*/

public function editProfilePicture() {
$parent = \P4\User::where('email', '=', Auth::user() -> email) -> get() -> first();
return view('parents.getprofilepicture') -> with(['parent' => $parent]);
}

public function processProfilePicture() {

if (empty($_FILES['images'])) {
echo json_encode(['error' => 'No files found for upload.']);
return;
}
$images = $_FILES['images'];
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];

$success = null;
$paths = ['.'];
$filenames = $images['name'];

for ($i = 0; $i < count($filenames); $i++) {
$ext = explode('.', basename($filenames[$i]));
$parent_picture_folder = "assets\\uploads\\" . $user_id;
$extension = array_pop($ext);
$target = "assets\\uploads\\" . $user_id . "\\" . $user_id . "." . $extension;
if (!is_dir($parent_picture_folder)) {
File::makeDirectory($parent_picture_folder, 0775, true);
} else {
foreach (glob($parent_picture_folder."\\*.*") as $filename) {
if (is_file($filename)) {
unlink($filename);
}
}
}

if (move_uploaded_file($images['tmp_name'][$i], $target)) {
$success = true;
$paths[] = "\\assets\\uploads\\" . $user_id . "\\" . $user_id . "." . $extension;
} else {
$success = false;
break;
}
}

if ($success === true) {
$output = ['uploaded' => $paths];
} else {
$output = ['error' => 'No files were processed.'];
}
echo json_encode($output);
}

public function postEditProfilePicture(Request $request) {
$parent = \P4\User::where('email', '=', $request -> email) -> get() -> first();
if ($request -> remove_profile_picture == "on") {
$parent -> picture_location = "";
}
if (!is_null($request -> picture_location_to_store) && ($request -> picture_location_to_store != "")) {
$parent -> picture_location = $request -> picture_location_to_store;
}

$parent -> save();
return view('parents.showparentsdetails') -> with(['parent' => $parent]);
}


}
10 changes: 9 additions & 1 deletion app/Http/Controllers/WelcomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

use P4\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;

class WelcomeController extends Controller {

/**
* Responds to requests to GET /P$
*/
public function index() {
return view('clapevents.index');
if (Auth::user()) {
$parent = \P4\User::where('id', '=', Auth::user()->id) -> get() -> first();
print_r($parent);
return view('parents.showparentsdetails') -> with(['parent' => $parent]);
} else {
return view('clapevents.index');
}
}

}
Loading

0 comments on commit 87d064a

Please sign in to comment.