public function index(Request $request)
 {
     $user = Login::where('remember_token', '=', $request->header('token'))->where('login_from', '=', $request->ip())->join('members', 'members.id', '=', 'logins.member_id')->where('logins.status', '=', '1')->first();
     if ($user->mtype != 3) {
         $returnData = array('status' => 'fail', 'mesage' => 'insufficient permision', 'code' => 403);
         return $returnData;
     }
     return $user;
 }
 public function postRegistrationForm(SignUpRequest $request)
 {
     $data = $request->all();
     //Demographic Insert
     /*
         Demographic details captured below are 
         the only values that are nessary for 
         users, customer demographics will use
         the same table however more details 
         will be required on the post array.
     */
     $demo = new Demographic();
     $demo->email = $data['email'];
     $demo->first_name = $data['name'];
     $demo->last_name = $data['usr_surname'];
     $demo->title_id = $data['usr_title'];
     $demo->d_active = 1;
     $demo->date = Carbon::now();
     $demo->save();
     //Password Insert
     /*
         Password input in Database must be salted
         there after the password must be stored in
         a separate password table so the password
         history can be maintained.
     */
     $pass = new Password();
     $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
     $password = hash('sha512', $data['p'] . $random_salt);
     $pass->password = $password;
     $pass->p_active = '1';
     $pass->p_date = Carbon::now();
     $pass->save();
     //Salt Insert
     /*
         Random Salt must be saved in database so that
         the password can be un-salted and compared to
         the user's password captured upon login.
     */
     $salt = new Salt();
     $salt->salt = $random_salt;
     $salt->save();
     //Creat Login and Associate to Demo/Pass/Salt
     /*
         Only once the required associated data is 
         captured can a login be created. It is 
         important to maintain an environment that 
         can be scaled out, we're doing this by 
         maintaining high levels of normalization.
     */
     $login = new Login();
     $login->login = $data['email'];
     $login->p_id = $pass->p_id;
     $login->s_id = $salt->s_id;
     $login->r_id = $data['usr_role'];
     $login->d_id = $demo->d_id;
     $login->usr_active = 0;
     $successfull = $login->save();
     //Get Security Control Key
     /*
         This function always certain security keys
         to be retireved from the database and used 
         in functions/arguments here.
     */
     //Set Email verification key
     /*
         To ensure that we are not spammed, we will
         need to only allow users/customer whom have
         a verified email address to login, therefore
         until the user verifies their email address 
         their login will not be active.
     */
     $email = new verify_emailaddress();
     $email->key = md5('3m@!l01' . time());
     $email->key_active = 1;
     $email->d_id = $demo->d_id;
     $email->save();
     //Open Route upon success/fail
     /*
         The below opens the route depending on the 
         outcome of the registration login model save.
     */
     if (!$successfull) {
         return redirect('signup_failed');
     } else {
         return redirect('signup_success');
     }
 }
 public function registerUser()
 {
     $name = Input::get('register_name');
     $email = Input::get('register_email');
     $username = Input::get('register_usr');
     $pass = Input::get('register_pass');
     $fileName = 'no_img.jpg';
     if (Input::file('register_photo')) {
         $file = array('image' => Input::file('register_photo'));
         // setting up rules
         $rules = array('image' => 'required');
         //mimes:jpeg,bmp,png and for max size max:10000
         // doing the validation, passing post data, rules and the messages
         $validator = Validator::make($file, $rules);
         if ($validator->fails()) {
             // send back to the page with the input data and errors
             //            return Redirect::to('login')->withInput()->withErrors($validator);
             //            print_r("error");
         }
         if (Input::file('register_photo')->isValid()) {
             $destinationPath = 'uploads';
             // upload path
             $extension = Input::file('register_photo')->getClientOriginalExtension();
             // getting image extension
             $fileName = rand(11111, 99999) . '.' . $extension;
             // renameing image
             Input::file('register_photo')->move($destinationPath, $fileName);
             // uploading file to given path
             // sending back with message
         }
     }
     Login::insertUser($name, $username, $pass, $fileName, $email);
     $this->sendEmail($email, $name);
     Redirect::to('login')->with('test', 'test')->send();
 }