Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anselmo jacyntho #21

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions challenge-one/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Como executar

```bash
php diff_between_diagonals.php
```

## Como alterar a matriz

Para alterar a matriz basta mudar os valores do array **$matrix**

```php

$matrix = [
[1,2,3],
[4,5,6],
[9,8,9]
];

```
32 changes: 32 additions & 0 deletions challenge-one/diff_between_diagonals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
];

$error = false;
$total_rows = count($matrix);

$primary = 0;
$second = 0;

foreach ( $matrix as $key => $row ) {
if ( count($row) != $total_rows ) {
$error = true;
break;
}

$primary += $row[$key];
$second += (array_slice($row, -(1+$key))[0]);
}

if ( $error ) {
echo "Desculpe! Aparentemente está não é uma Matriz Quadrada \n";
exit;
}

$diff = $primary - $second;

echo "A diferença entre as diagonais é: {$diff} \n";
15 changes: 15 additions & 0 deletions challenge-two/user_register/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
20 changes: 20 additions & 0 deletions challenge-two/user_register/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
APP_NAME="User Register"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost:8000

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

MLEARN_HOST=URL_DO_AMBIENTE
MLEARN_AUTHORIZATION=SUA_CHAVE_DE_AUTORIZACAO
MLEARN_SERVICE_ID=SEU_SERVICE_ID
MLEARN_USERS_GROUP_ID=SEU_GROUP_ID
5 changes: 5 additions & 0 deletions challenge-two/user_register/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
13 changes: 13 additions & 0 deletions challenge-two/user_register/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
13 changes: 13 additions & 0 deletions challenge-two/user_register/.styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
php:
preset: laravel
disabled:
- no_unused_imports
finder:
not-name:
- index.php
- server.php
js:
finder:
not-name:
- webpack.mix.js
css: true
55 changes: 55 additions & 0 deletions challenge-two/user_register/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
### Requisitos

- PHP >= 7.2.5
- BCMath PHP Extension
- Ctype PHP Extension
- Fileinfo PHP extension
- JSON PHP Extension
- Mbstring PHP Extension
- OpenSSL PHP Extension
- PDO PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
- Node.js >= 14.0
- Npm >= 6.0
- Mysql >= 5.7

### Configurando ambiente

1. Crie um banco de dados em seu mysql
2. Navegue até a raiz do projeto e renomeie o arquivo **.env-example** para **.env**
3. Substitua os dados de conexão ao banco de dados e a api MLEARN no arquivo **.env ** recém renomeado

```bash
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

MLEARN_HOST=URL_DO_AMBIENTE
MLEARN_AUTHORIZATION=SUA_CHAVE_DE_AUTORIZACAO
MLEARN_SERVICE_ID=SEU_SERVICE_ID
MLEARN_USERS_GROUP_ID=SEU_GROUP_ID
```
4.Navegue para a raiz do projeto e execute os comandos abaixo:

```bash
composer install
npm install
npm run dev
php artisan key:generate
php artisan migrate
```

### Acessando o projeto

Na raiz do projeto execute o comando:

```bash
php artisan serve
```

Acesse o endereço:
[http://localhost:8000/](http://localhost:8000/ "http://localhost:8000/")
41 changes: 41 additions & 0 deletions challenge-two/user_register/app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
40 changes: 40 additions & 0 deletions challenge-two/user_register/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}
43 changes: 43 additions & 0 deletions challenge-two/user_register/app/Http/Apis/MLearnApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Apis;

use Illuminate\Support\Facades\Http;

class MLearnApi {

protected $host;
protected $headers;

public function __construct()
{
$this->host = config('mlearn.host');;

$this->headers = [
'Authorization' => "Bearer " . config('mlearn.auth'),
'service-id' => config('mlearn.service_id'),
'app-users-group-id' => config('mlearn.user_group_id')
];
}

public function activateUser($user)
{
return Http::withHeaders($this->headers)->post("{$this->host}/integrator/{$this->headers['service-id']}/users", [
"msisdn" => $user['phone'],
"name" => $user['name'],
"access_level" => $user['account'],
"password" => $user['password'],
"external_id" => $user['id']
]);
}

public function upgradeAccount($access_id)
{
return Http::withHeaders($this->headers)->put("{$this->host}/integrator/{$this->headers['service-id']}/users/{$access_id}/upgrade");
}

public function downgradeAccount($access_id)
{
return Http::withHeaders($this->headers)->put("{$this->host}/integrator/{$this->headers['service-id']}/users/{$access_id}/downgrade");
}
}
13 changes: 13 additions & 0 deletions challenge-two/user_register/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
66 changes: 66 additions & 0 deletions challenge-two/user_register/app/Http/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}
Loading