Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
3,966 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
/* | ||
| ------------------------------------------------------------------------- | ||
| URI ROUTING | ||
| ------------------------------------------------------------------------- | ||
| This file lets you re-map URI requests to specific controller functions. | ||
| | ||
| Typically there is a one-to-one relationship between a URL string | ||
| and its corresponding controller class/method. The segments in a | ||
| URL normally follow this pattern: | ||
| | ||
| example.com/class/method/id/ | ||
| | ||
| In some instances, however, you may want to remap this relationship | ||
| so that a different class/function is called than the one | ||
| corresponding to the URL. | ||
| | ||
| Please see the user guide for complete details: | ||
| | ||
| http://codeigniter.com/user_guide/general/routing.html | ||
| | ||
*/ | ||
|
||
$route['auth/callback/:any'] = '/'; | ||
|
||
/* End of file routes.php */ | ||
/* Location: ./application/config/routes.php */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
$this->url = 'http://localhost/as-wcp/index.php/auth/github/callback/'; | ||
$this->url_success = 'http://localhost/as-wcp/index.php/auth/github/callback/sucess'; | ||
$this->key = '02a3aa14b1f050673afa'; | ||
|
||
$this->secret = 'c419711862371fbbad8a51f6d0bcc2768300734a'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
|
||
class Callback extends MX_Controller | ||
{ | ||
|
||
function index() | ||
{ | ||
require_once dirname(__file__).'/_config.php'; | ||
$this->load->helper('url'); | ||
$this->load->library('session'); | ||
|
||
if( (!isset($_GET['code'])) || empty($_GET['code']) || trim($_GET['code']) == '' ) | ||
return redirect('auth/github/login'); | ||
|
||
print_r($_GET['code']); | ||
|
||
$this->load->library('curl'); | ||
|
||
$request = $this->curl->new_request('https://github.com/login/oauth/access_token?client_id='.$this->key.'&redirect_uri='.$this->url_success.'&client_secret='.$this->secret.'&code='.$_GET['code']); | ||
|
||
$response = $request->execute(); | ||
|
||
foreach(explode('&', $response->get_response()) as $header) | ||
{ | ||
list($key, $value) = explode('=', $header); | ||
|
||
switch($key) | ||
{ | ||
|
||
case 'error': | ||
show_error($value); | ||
break; | ||
|
||
case 'access_token': | ||
$this->session->set_userdata('github_logged_in', true); | ||
$this->session->set_userdata('github_access_token', $value); | ||
break; | ||
|
||
default: | ||
print_r($header); | ||
break; | ||
} | ||
} | ||
|
||
redirect('auth/github/callback/connect'); | ||
} | ||
|
||
function connect() | ||
{ | ||
$this->load->library('session'); | ||
$this->load->library('curl'); | ||
|
||
$this->load->model('external_user_m'); | ||
|
||
if($this->session->userdata('github_logged_in')) | ||
{ | ||
#https://github.com/api/v2/json OR xml/user/show?access_token=XXX | ||
$request = $this->curl->new_request('https://github.com/api/v2/xml/user/show?access_token='.$this->session->userdata('github_access_token')); | ||
$response = $request->execute(); | ||
|
||
$user = new SimpleXMLElement($response->get_response()); | ||
|
||
print_r($user); | ||
} | ||
else | ||
show_error('please auth to github first'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
class Login extends MX_Controller | ||
{ | ||
|
||
function _go() | ||
{ | ||
$scopes = array(); | ||
|
||
$allow = $this->input->post('allow_usr'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'user_access') | ||
$scopes[] = 'user'; | ||
unset($allow); | ||
|
||
$allow = $this->input->post('allow_pub_repo'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'pub_repo') | ||
$scopes[] = 'public_repo'; | ||
unset($allow); | ||
|
||
$allow = $this->input->post('allow_repo'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'repo') | ||
$scopes[] = 'repo'; | ||
unset($allow); | ||
|
||
$allow = $this->input->post('allow_gist'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'gist') | ||
$scopes[] = 'gist'; | ||
unset($allow); | ||
|
||
header('Location: https://github.com/login/oauth/authorize?client_id='.$this->key.'&redirect_uri='.rawurlencode($this->url).'&scope='.implode($scopes, ',')); | ||
} | ||
|
||
function index() | ||
{ | ||
require_once dirname(__file__).'/_config.php'; | ||
$this->load->library('form'); | ||
|
||
$this->form | ||
->open('auth/github/login') | ||
->label('auth with github?') | ||
->checkbox('auth', 'user_access', 'allow this site to auth you with your github account', true, 'required') | ||
->checkbox('allow_usr', 'user_access', 'see profile information', true) | ||
->checkbox('allow_pub_repo', 'pub_repo', 'see public repos') | ||
->checkbox('allow_repo', 'repo', 'see all your repos') | ||
->checkbox('allow_gist', 'gist', 'allow access to your gists') | ||
->onsuccess(array($this, '_go'), '') | ||
|
||
->submit('proceed'); | ||
|
||
echo $this->form->errors; | ||
echo $this->form->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
$this->url = 'http://localhost/as-wcp/index.php/auth/google/callback/'; | ||
$this->url_success = 'http://localhost/as-wcp/index.php/auth/google/callback/sucess'; | ||
$this->key = '28738921351.apps.googleusercontent.com'; | ||
|
||
$this->secret = 'vz_bxAHKhCS27ImdfAQUFx0Y'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
|
||
class Callback extends MX_Controller | ||
{ | ||
|
||
function index() | ||
{ | ||
require_once dirname(__file__).'/_config.php'; | ||
$this->load->helper('url'); | ||
$this->load->library('session'); | ||
|
||
if( (!isset($_GET['code'])) || empty($_GET['code']) || trim($_GET['code']) == '' ) | ||
return redirect('auth/google/login'); | ||
|
||
print_r($_GET['code']); | ||
|
||
$this->load->library('curl'); | ||
|
||
$request = $this->curl->new_request('http://accounts.google.com/o/oauth2/token'); | ||
|
||
$request->set_request_method('post'); | ||
|
||
$request->set_post_var('code', $_GET['code']); | ||
$request->set_post_var('client_id', $this->key); | ||
$request->set_post_var('client_secret', $this->secret); | ||
$request->set_post_var('redirect_uri', $this->url); | ||
$request->set_post_var('rant_type', 'authorization_code'); | ||
|
||
try | ||
{ | ||
$response = $request->execute(); | ||
} | ||
catch(Exception $e) | ||
{ | ||
echo 'Error: '.$e->getMessage(); | ||
print_r($request); | ||
} | ||
|
||
foreach(explode('&', $response->get_response()) as $header) | ||
{ | ||
list($key, $value) = explode('=', $header); | ||
|
||
switch($key) | ||
{ | ||
|
||
case 'error': | ||
show_error($value); | ||
break; | ||
|
||
case 'access_token': | ||
$this->session->set_userdata('github_logged_in', true); | ||
$this->session->set_userdata('github_access_token', $value); | ||
break; | ||
|
||
default: | ||
print_r($header); | ||
break; | ||
} | ||
} | ||
|
||
//redirect('auth/github/callback/connect'); | ||
} | ||
|
||
function connect() | ||
{ | ||
$this->load->library('session'); | ||
$this->load->library('curl'); | ||
|
||
$this->load->model('external_user_m'); | ||
|
||
if($this->session->userdata('github_logged_in')) | ||
{ | ||
#https://github.com/api/v2/json OR xml/user/show?access_token=XXX | ||
$request = $this->curl->new_request('https://github.com/api/v2/xml/user/show?access_token='.$this->session->userdata('github_access_token')); | ||
$response = $request->execute(); | ||
|
||
$user = new SimpleXMLElement($response->get_response()); | ||
|
||
print_r($user); | ||
} | ||
else | ||
show_error('please auth to github first'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
class Login extends MX_Controller | ||
{ | ||
|
||
function _go() | ||
{ | ||
$scopes = array(); | ||
|
||
$allow = $this->input->post('allow_usr'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'user_access') | ||
$scopes[] = 'user'; | ||
unset($allow); | ||
|
||
$allow = $this->input->post('allow_pub_repo'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'pub_repo') | ||
$scopes[] = 'public_repo'; | ||
unset($allow); | ||
|
||
$allow = $this->input->post('allow_repo'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'repo') | ||
$scopes[] = 'repo'; | ||
unset($allow); | ||
|
||
$allow = $this->input->post('allow_gist'); | ||
if(is_array($allow) && isset($allow[0]) && $allow[0] == 'gist') | ||
$scopes[] = 'gist'; | ||
unset($allow); | ||
|
||
header('Location: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id='.$this->key.'&redirect_uri='.rawurlencode($this->url).'&scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'); | ||
#.'&scope='.implode($scopes, ',')); | ||
} | ||
|
||
function index() | ||
{ | ||
require_once dirname(__file__).'/_config.php'; | ||
$this->load->library('form'); | ||
|
||
$this->form | ||
->open('auth/google/login') | ||
->label('auth with github?') | ||
->checkbox('auth', 'user_access', 'allow this site to auth you with your github account', true, 'required') | ||
->checkbox('allow_usr', 'user_access', 'see profile information', true) | ||
->checkbox('allow_pub_repo', 'pub_repo', 'see public repos') | ||
->checkbox('allow_repo', 'repo', 'see all your repos') | ||
->checkbox('allow_gist', 'gist', 'allow access to your gists') | ||
->onsuccess(array($this, '_go'), '') | ||
|
||
->submit('proceed'); | ||
|
||
echo $this->form->errors; | ||
echo $this->form->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
class External_user_m extends CI_Model | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
class Contact extends MX_Controller | ||
{ | ||
function index() | ||
{ | ||
$this->load->library('template'); | ||
$this->load->library('Parser'); | ||
$this->load->library('form'); | ||
$this->load->model('site_settings'); | ||
$this->load->helper('url'); | ||
|
||
#create form | ||
$this->form | ||
->open('contact/') | ||
->text('name', 'your name', 'trim|max_length[50]|xss_clean') | ||
->text('email', 'your email adress <sub>(won't be published)</sub>', 'email|trim|max_length[50]|xss_clean') | ||
|
||
->text('subject', 'the subject of your message', 'trim|max_length[50]|xss_clean') | ||
->textarea('message', 'Your message', 'trim|xss_clean') | ||
->indent(200); | ||
|
||
if(1 == (int)$this->site_settings->get_setting('contact_use_captcha', '1')) | ||
$this->form->recaptcha('Please enter the captcha code'); | ||
|
||
$this->form | ||
->submit() | ||
->reset() | ||
|
||
->model('contact_m', 'contact'); | ||
#->onsuccess('redirect', 'contacted'); | ||
|
||
$data['form'] = $this->form->get(); // this returns the validated form as a string | ||
$data['errors'] = $this->form->errors; // this returns validation errors as a string | ||
|
||
switch($this->router->content_type) | ||
{ | ||
default: | ||
case 'html': | ||
$this->template | ||
->set_title('contact us') | ||
->add_head('<link href="'.base_url('static/form.css').'" rel="stylesheet" type="text/css" />') | ||
->build('contact_view', $data); | ||
break; | ||
|
||
case 'json': | ||
$this->output->set_status_header(400); | ||
$this->output->set_output(json_encode(array('error' => array('code' => 400, 'message' => 'this page is not available for ajax (yet?)')))); | ||
break; | ||
|
||
case 'xml': | ||
$this->output->set_status_header(400); | ||
$this->output->set_output('<pages><page status="400" message="this page is not available for ajax (yet?)" /> </pages>'); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
class Contact_m extends CI_Model | ||
{ | ||
function contact(&$forum, $data) | ||
{ | ||
$this->load->model('site_settings'); | ||
$mail_adress = $this->site_settings->get_setting('contact_email', 'user@domain.tld'); | ||
|
||
$this->load->library('email'); | ||
|
||
$this->email->from($data['email'], $data['name']); | ||
$this->email->to($mail_adress); | ||
|
||
$this->email->subject($data['subject']); | ||
$this->email->message($data['message']); | ||
|
||
if(!$this->email->send()) | ||
$form->add_error('email', 'A contact email could not be sent, please try again'); | ||
} | ||
|
||
} |
Oops, something went wrong.