Skip to content

Commit

Permalink
updating routes/web
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremiahiro committed Jun 27, 2020
2 parents 8403837 + 812d5f2 commit e7ee4fb
Show file tree
Hide file tree
Showing 451 changed files with 2,803 additions and 779 deletions.
Empty file modified .editorconfig 100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions .env.example
Expand Up @@ -4,6 +4,8 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

API_URL=https://dev.customerpay.me

LOG_CHANNEL=stack

DB_CONNECTION=mysql
Expand Down
Empty file modified .gitattributes 100644 → 100755
Empty file.
Empty file modified .gitignore 100644 → 100755
Empty file.
Empty file modified .styleci.yml 100644 → 100755
Empty file.
Empty file modified Procfile 100644 → 100755
Empty file.
71 changes: 70 additions & 1 deletion README.md 100644 → 100755
@@ -1 +1,70 @@
# mycustomer
# mycustomer

<div align="center">

![hng](https://res.cloudinary.com/iambeejayayo/image/upload/v1554240066/brand-logo.png)

<br>

</div>

# Installation Guide

- Install [Composer](https://getcomposer.org) & [Laravel](https://laravel.com)
<br>



Fork The Repo And Clone Your Fork

```bash
cd sentry-my-customer-frontend
```
```bash
git remote add upstream https://github.com/hngi/sentry-my-customer-frontend.git
```

```bash
git pull upstream develop
```

```bash
cp `.env.example` to `.env`
```

```bash
composer install
```

```bash
php artisan serve
```


Visit localhost:8000 in your browser


When You Make Changes

```bash
git add .
```

```bash
git commit _m "commit message"
```
```bash
git pull upstream develop
```
Make Sure there is no conflict

```bash
git push origin develop
```
Then Create Your Pull Request

- **Also Add description of what you did in your pull request** <br>



# Contribution Guide
Empty file modified app/Console/Kernel.php 100644 → 100755
Empty file.
Empty file modified app/Exceptions/Handler.php 100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions app/Http/Controllers/ActivateController.php
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cookie;

class ActivateController extends Controller
{
//

public function index()
{
if (Cookie::get('is_active') == true) {
return redirect()->route('dashboard');
}

$api_token = Cookie::get('api_token');
$phone_number = Cookie::get('phone_number');
return view("backend.activate.activate")->withApiToken($api_token)->withPhoneNumber($phone_number);
}
}
Empty file modified app/Http/Controllers/Auth/ConfirmPasswordController.php 100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/ForgotPasswordController.php 100644 → 100755
Empty file.
87 changes: 86 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php 100644 → 100755
Expand Up @@ -5,6 +5,12 @@
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Log;

// use Illuminate\Support\Facades\Http;

class LoginController extends Controller
{
Expand All @@ -27,6 +33,7 @@ class LoginController extends Controller
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
protected $host;

/**
* Create a new controller instance.
Expand All @@ -35,6 +42,84 @@ class LoginController extends Controller
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->host = env('API_URL', 'https://customerpay.me/');
}

public function index()
{
if (Cookie::get('api_token')){
return redirect()->route('dashboard');
}
return view('backend.login');
}

public function authenticate(Request $request)
{
$validation = Validator::make(request()->all(),[
'phone_number' => 'required|numeric|digits_between:1,16',
'password' => 'required'
]);

if ($validation->fails()) {
$request->session()->flash('message', 'Invalid Phone number or password');
$request->session()->flash('alert-class', 'alert-danger');
return redirect()->route('login');
}

try {
$client = new \GuzzleHttp\Client();
$response = $client->post($this->host . '/user', [
'form_params' => [
'phone_number' => $request->input('phone_number'),
'password' => $request->input('password')
]
]);

if ($response->getStatusCode() == 200) {
$response = json_decode($response->getBody());

if (isset($response->Status) || (isset($response->Status) && !$response->status)) {
$request->session()->flash('message', $response->Message);
$request->session()->flash('alert-class', 'alert-danger');
return redirect()->route('login');
}

// get data from response
$api_token = $response->api_token;
$phone_number = $response->user->phone_number;
$first_name = $response->user->first_name;
$last_name = $response->user->last_name;
$email = $response->user->email;
$is_active = $response->user->is_active;

// store data to cookie

Cookie::queue('api_token', $api_token);
Cookie::queue('is_actives', $is_active);
Cookie::queue('phone_number', $phone_number);

//check if active
if ($is_active == false) {
return redirect()->route('activate.user');
}

// store other data to cookie
Cookie::queue('first_name', $first_name);
Cookie::queue('last_name', $last_name);
Cookie::queue('email', $email);

return redirect()->route('dashboard');
}

if ($response->getStatusCode() == 500) {
return view('errors.500');
}
} catch (\Exception $e) {
// log $e->getMessage() when error loggin is setup
Log::error("catch error: LoginController - ".$e->getMessage());
$request->session()->flash('message', 'something went wrong try again in a few minutes');
return redirect()->route('login');
}
return redirect()->route('login');
}
}
57 changes: 49 additions & 8 deletions app/Http/Controllers/Auth/RegisterController.php 100644 → 100755
Expand Up @@ -4,10 +4,12 @@

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Cookie;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class RegisterController extends Controller
{
Expand Down Expand Up @@ -56,18 +58,57 @@ protected function validator(array $data)
]);
}

public function index() {
return view('backend.register.signup');
}

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
// Controller action to register a new user.
public function register(Request $request)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
try {
// check if all fields are available
if ($request->all()) {
// make an api call to register the user
$client = new Client();
$response = $client->post(env('API_URL') . '/register/user', [
'form_params' => [
'first_name' => $request->input('first_name'),
'last_name' => $request->input('last_name'),
'email' => $request->input('email'),
'phone_number' => $request->input('phone_number'),
'password' => $request->input('password')
]
]);

if ($response->getStatusCode() == 201) {
$res = json_decode($response->getBody());
// get the api_token and phone_number from the response
$api_token = $res->User->api_token;
$phone_number = $res->User->phone_number;

// set api_token and phone number cookie
Cookie::queue('api_token',
$api_token
);
Cookie::queue('phone_number', $phone_number);
return redirect('/backend/activate');
}

if ($response->getStatusCode() == 500) {
return view('errors.500');
}
} else {
return redirect('/backend/register');
}
} catch (\Exception $e) {
Log::error('Catch error: RegisterController - '. $e->getMessage());
return view('errors.500');
}
}
}
Empty file modified app/Http/Controllers/Auth/ResetPasswordController.php 100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/VerificationController.php 100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Controller.php 100644 → 100755
Empty file.

0 comments on commit e7ee4fb

Please sign in to comment.