Skip to content

Commit

Permalink
Buisiness logic for Facebook login. Refs #20
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed May 25, 2015
1 parent cb3f77a commit a64e36f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
54 changes: 54 additions & 0 deletions application/controllers/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,60 @@ function checkEmail()
echo json_encode($result);
}
}

function facebookSignup()
{
if($this->input->post('email'))
{
$result = array();

$password = "FB_"+$this->input->post('id');
$name = $this->input->post('name');
$firstname = $this->input->post('firstname');
$timezone = $this->input->post('timezone');
$country = $this->input->post('country');

if($this->user->signup($email, $password, $name, $firstname, $timezone, $country))
{
$this->load->helper('mcapi');
$api = new MCAPI('eff18c4c882e5dc9b4c708a733239c82-us9');
$api->listSubscribe('7f94c4aa71', $email, '');

$this->load->library('email');

$config['protocol'] = "smtp";
$config['smtp_host'] = "smtp.mandrillapp.com";
$config['smtp_port'] = "587";
$config['smtp_user'] = "[email protected]";
$config['smtp_pass'] = "pUOMLUusBKdoR604DpcOnQ";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$this->email->initialize($config);

$this->email->from('[email protected]', 'Toolwatch');
$this->email->to($email, $name.' '.$firstname);
$this->email->reply_to('[email protected]', 'Toolwatch');

$this->email->subject('Welcome to Toolwatch!');

$message = $this->load->view('email/signup', '', true);
$this->email->message($message);

if($this->email->send())
{
$result['success'] = "signup";
$this->user->login($email, $password);
}
}else if($this->user->login($email, $password)){
$result['success'] = "signin";
}else {
$result['success'] = false;
}
echo json_encode($result);
}
}

function signup()
{
Expand Down
22 changes: 19 additions & 3 deletions assets/js/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,24 @@
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';

$.post('/ajax/signup', {email: response.email, name: response.name, firstname: response.first_name, timezone: response.timezone, country: response.country}, function(data)
{
var result = $.parseJSON(data);
if(result.success == "signup")
{
$.post('/sign-up-success/', {ajax: true}, function(data)
{
$('#pageModal .modal-body').html(data);
setTimeout('window.location.replace("/measures/")', 5000);
});
}else if(result.success == "signin"){
setTimeout('window.location.replace("/measures/")', 1000);

} else {
$('.global-error').html('Something went wrong... Try again later.').show();
}
});
console.log(response);
});
}

0 comments on commit a64e36f

Please sign in to comment.