Skip to content
This repository was archived by the owner on Jul 12, 2019. It is now read-only.

Commit d9959bd

Browse files
committed
Fixed merge conflict in multiple files.
2 parents 93704d0 + 03030b6 commit d9959bd

19 files changed

+449
-253
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
SLACK_CLIENT_ID=
22
SLACK_CLIENT_SECRET=
3-
SLACK_REDIRECT_CALLBACK_URL=http://localhost:8880/authorize
43
SLACK_VERIFICATION_TOKEN=
54

65
APP_ENV=local
@@ -15,4 +14,4 @@ LINXER_DB_URL=postgres://USERNAME:PASSWORD@HOSTNAME:PORT/DATABASE
1514
BROADCAST_DRIVER=log
1615
CACHE_DRIVER=file
1716
SESSION_DRIVER=file
18-
QUEUE_DRIVER=sync
17+
QUEUE_DRIVER=sync

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace App\Http\Controllers\Auth;
44

5-
use App\User;
65
use App\Http\Controllers\Controller;
7-
use Illuminate\Support\Facades\Validator;
6+
use App\User;
87
use Illuminate\Foundation\Auth\RegistersUsers;
8+
use Illuminate\Support\Facades\Validator;
99

1010
class RegisterController extends Controller
1111
{
@@ -42,7 +42,7 @@ public function __construct()
4242
/**
4343
* Get a validator for an incoming registration request.
4444
*
45-
* @param array $data
45+
* @param array $data
4646
* @return \Illuminate\Contracts\Validation\Validator
4747
*/
4848
protected function validator(array $data)
@@ -57,7 +57,7 @@ protected function validator(array $data)
5757
/**
5858
* Create a new user instance after a valid registration.
5959
*
60-
* @param array $data
60+
* @param array $data
6161
* @return User
6262
*/
6363
protected function create(array $data)

app/Http/Controllers/AuthController.php

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,27 @@ class AuthController extends Controller
1010
{
1111
public function authorizeSlack()
1212
{
13-
$code=$_GET['code'];
14-
$client=new Client();
15-
$response=$client->request('GET', 'https://slack.com/api/oauth.access',
16-
['query' => ['client_id' => '104593454705.107498116711',
17-
'client_secret' => env('SLACK_CLIENT_SECRET'),
18-
'redirect_uri' => urlencode(env('APP_URL').'/authorize'),
19-
'code' => $code]]);
20-
$response=json_decode($response->getBody(), true);
21-
if($response['ok']===true) {
22-
if(isset($response['access_token'])) {
23-
$credential=new Credential();
24-
$credential->access_token=$response['access_token'];
25-
$credential->team_id=$response['team_id'];$credential->bot_user_id=$response['bot']['bot_user_id'];
26-
$credential->bot_access_token=$response['bot']['bot_access_token'];
27-
$credential->save();
28-
}
29-
else {
30-
Storage::put('token.dat', $response['stuff']['access_token']);
31-
}
32-
$result="Authorized";
33-
}
34-
else {
35-
$result=$response['error'];
36-
}
37-
return view('authorize', ['result' => $result]);
13+
$code = $_GET['code'];
14+
$client = new Client();
15+
$response = $client->request('GET', 'https://slack.com/api/oauth.access',
16+
['query' => ['client_id' => '104593454705.107498116711',
17+
'client_secret' => env('SLACK_CLIENT_SECRET'),
18+
'code' => $code]]);
19+
$response = json_decode($response->getBody(), true);
20+
if ($response['ok'] === true) {
21+
if (isset($response['access_token'])) {
22+
$credential = new Credential();
23+
$credential->access_token = $response['access_token'];
24+
$credential->team_id = $response['team_id'];
25+
$credential->bot_user_id = $response['bot']['bot_user_id'];
26+
$credential->bot_access_token = $response['bot']['bot_access_token'];
27+
$credential->save();
28+
}
29+
$result = "Authorized";
30+
} else {
31+
$result = $response['error'];
32+
}
33+
return view('Auth/add', ['result' => $result]);
3834
}
3935

4036
/* Redirects user to teams links Page
@@ -43,41 +39,25 @@ public function authorizeSlack()
4339
*/
4440
public function redirectUsertoTeamLinks()
4541
{
46-
$code=$_GET['code'];
47-
$client=new Client();
48-
$response=$client->request('GET', 'https://slack.com/api/oauth.access',
49-
['query' => ['client_id' => '104593454705.107498116711',
50-
'client_secret' => env('SLACK_CLIENT_SECRET'),
51-
'redirect_uri' => urlencode(env('APP_URL').'/signin'),
52-
'code' => $code]]);
53-
$response=json_decode($response->getBody(), true);
54-
if($response['ok']===true)
55-
{
56-
if(isset($response['access_token']))
57-
{
58-
$access_token=$response['access_token'];
59-
$slackUsers = $this->getUserFromToken($access_token);
60-
$teamName = $slackUsers['team']['name'];
61-
$teamId = $slackUsers['team']['id'];
62-
63-
return redirect("/links/$teamId-$teamName");
42+
$code = $_GET['code'];
43+
$client = new Client();
44+
$response = $client->request('GET', 'https://slack.com/api/oauth.access',
45+
['query' => ['client_id' => '104593454705.107498116711',
46+
'client_secret' => env('SLACK_CLIENT_SECRET'),
47+
'redirect_uri' => 'http://linxer.herokuapp.com/Auth/signin',
48+
'code' => $code]]);
49+
$response = json_decode($response->getBody(), true);
50+
$team_id = $response['team']['id'];
51+
$access_token = $response['access_token'];
52+
if ($response['ok'] === true) {
53+
$interactUser = $client->request('GET', 'https://slack.com/api/users.identity?token=' . $access_token);
54+
$interactResponse = json_decode($interactUser->getBody()->getContents(), true);
55+
$teamId = $interactResponse['team']['id'];
56+
$teamName = $interactResponse['team']['name'];
57+
return redirect("/links/$teamId-$teamName");
58+
} else {
59+
$errorMsg = $response['error'];
6460
}
65-
else
66-
{
67-
$errorMsg=$response['error'];
68-
}
69-
return view('authorize', ['result' => $errorMsg]);
70-
}
71-
}
72-
73-
/* Get User details from slack generated token */
74-
75-
public function getUserFromToken($token)
76-
{
77-
$options = ['headers' => ['Accept' => 'application/json']];
78-
$endpoint = 'https://slack.com/api/users.identity?token='.$token;
79-
$response = $this->getHttpClient()->get($endpoint, $options)->getBody()->getContents();
80-
81-
return json_decode($response, true);
61+
return view('Auth/signin', ['result' => $errorMsg]);
8262
}
8363
}

app/Http/Controllers/BotController.php

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace App\Http\Controllers;
44

55
use App\Http\Middleware\EventsMiddleware;
6+
use App\Models\Credential;
67
use GuzzleHttp\Client;
78
use Illuminate\Http\Request;
8-
use App\Models\Credential;
99

1010
class BotController extends Controller
1111
{
@@ -19,65 +19,71 @@ function __construct()
1919

2020
/**
2121
* Handles events received from Slack
22+
* @param Request $request
23+
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
2224
*/
2325
public function receive(Request $request)
2426
{
25-
$text=$request->input('event.text');
27+
response('Ok', 200);
28+
$text = $request->input('event.text');
2629
$data = [];
27-
if ($this->parseText($text)['type']=='add') {
30+
if ($this->parseText($text)['type'] == 'add') {
2831
$data['text'] = "Done! See all your team's links here. :blush:";
2932
$data['channel'] = $request->input('event.channel');
33+
$data['team_id'] = $request->input('team_id');
3034
$data['response_type'] = "saved";
31-
35+
3236
$this->respond($data);
33-
34-
return response('Ok', 200);
3537
}
3638

3739
}
3840

41+
public function parseText($text)
42+
{
43+
$tokens = explode(' ', $text);
44+
if ($tokens[0] == "@linxer") {
45+
if ($tokens[1] == "add" || $tokens[1] == "save") {
46+
return array(
47+
'type' => 'add',
48+
'link' => $tokens[2],
49+
'tags' => array_slice($tokens, 3));
50+
} else if ($tokens[1] == "find" || $tokens[1] == "search") {
51+
return array(
52+
'type' => 'search',
53+
'query_terms' => array_slice($tokens, 2));
54+
}
55+
}
56+
}
57+
3958
/**
4059
* Posts responses to Slack
4160
*/
4261
public function respond(array $data)
4362
{
44-
//if ($data['response_type'] == 'saved')
45-
$client=new Client();
46-
$response=$client->request('GET', 'https://slack.com/api/chat.postMessage',
47-
['query' => [
48-
'token' => Credential::where('team_id', $data['team_id'])->first()->bot_user_token;
49-
'channel'=> $data['channel'],
50-
'text' => $data['text']]]);
51-
return json_decode($response->getBody(), true);
63+
//if ($data['response_type'] == 'saved')
64+
$client = new Client();
65+
$response = $client->request('GET', 'https://slack.com/api/chat.postMessage',
66+
['query' => [
67+
'token' => Credential::where('team_id', $data['team_id'])->first()->bot_access_token,
68+
'channel' => $data['channel'],
69+
'text' => $data['text']
70+
]
71+
]);
72+
return json_decode($response->getBody(), true);
5273
}
5374

54-
public function parseText($text)
75+
public function test()
5576
{
56-
$tokens=explode(' ', $text);
57-
if($tokens[0]=="@linxer") {
58-
if($tokens[1]=="add" || $tokens[1]=="save") {
59-
return array( 'type' => 'add',
60-
'link' => $tokens[2],
61-
'tags' => array_slice($tokens, 3));
62-
} else if ($tokens[1]=="find" || $tokens[1]=="search") {
63-
return array( 'type' => 'search',
64-
'query_terms' => array_slice($tokens, 2));
65-
}
66-
}
67-
}
68-
69-
public function test()
70-
{
7177
$data = [];
72-
$data['text'] = "Done! See all your team's links here. :blush:";
73-
$data['channel'] = "#library-bot";
74-
$data['response_type'] = "saved";
75-
$data['team_id']="T";
76-
77-
$response=$this->respond($data);
78-
if($response['ok']===true) {
79-
return view('authorize', ['result' => "OK"]);
80-
} else return view('authorize', ['result' => $response['error']]);
81-
}
78+
$data['text'] = "Hi guys... @channel :blush:";
79+
$data['channel'] = "#bot-testing";
80+
$data['response_type'] = "saved";
81+
$data['team_id'] = "T32HFDCLR";
82+
83+
$response = $this->respond($data);
84+
if ($response['ok'] === true) {
85+
return view('Auth/add', ['result' => "OK"]);
86+
} else return view('Auth/add', ['result' => $response['error']]);
87+
}
8288

8389
}

app/Http/Controllers/Controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace App\Http\Controllers;
44

5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
56
use Illuminate\Foundation\Bus\DispatchesJobs;
6-
use Illuminate\Routing\Controller as BaseController;
77
use Illuminate\Foundation\Validation\ValidatesRequests;
8-
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
8+
use Illuminate\Routing\Controller as BaseController;
99

1010
class Controller extends BaseController
1111
{

app/Http/Controllers/WebController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace App\Http\Controllers;
44

5+
<<<<<<< HEAD
56
use Illuminate\Http\Request;
67
use App\Models\Link;
8+
=======
9+
>>>>>>> 03030b6375d5abd394236c49d6373308ad0ea94a
710
/**
811
* Handles requests through the browser ie at the live site
912
*/
@@ -30,6 +33,7 @@ public function viewLinks($teamSlug)
3033
// //$results=getAllLinks($teamId);
3134
// return view('listing', ["teamName" => $teamName, "results" => $results]);
3235
// }
36+
3337
}
3438

3539

app/Models/BaseModel.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
use Illuminate\Http;
99

1010
class BaseModel extends Model {
11-
use SoftDeletes;
12-
13-
//add a date column
14-
protected $dates = ['deleted_at'];
15-
1611

1712
public function selectQuery($sql_stmt) {
1813
return DB::select($sql_stmt);
@@ -21,4 +16,4 @@ public function selectQuery($sql_stmt) {
2116
public function sqlStatement($sql_stmt) {
2217
return DB::statement($sql_stmt);
2318
}
24-
}
19+
}

app/Models/Credential.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
?php
1+
<?php
22
namespace App\Models;
33

4-
class Credential extends BaseModel {
4+
class Credential extends BaseModel
5+
{
6+
7+
protected $guarded=[];
8+
}
59

6-
7-
protected $guarded=[];
8-
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"laravel/framework": "5.3.*",
1010
"laravel/socialite": "^2.0",
1111
"guzzlehttp/guzzle": "~6.0",
12-
"fzaninotto/faker": "^1.6"
12+
"fzaninotto/faker": "^1.6",
13+
"bramdevries/oauth2-slack": "^0.1.0"
1314
},
1415
"require-dev": {
1516
"mockery/mockery": "0.9.*",

0 commit comments

Comments
 (0)