Skip to content

Commit

Permalink
email unstable #35
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Aug 29, 2015
1 parent 1377bc8 commit 02776fb
Show file tree
Hide file tree
Showing 28 changed files with 4,244 additions and 3,576 deletions.
41 changes: 41 additions & 0 deletions CREATE TABLE `tw_ci`.`Email` (
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CREATE TABLE `tw_ci`.`email_user` (
`id` INT NOT NULL AUTO_INCREMENT,
`userId` INT NOT NULL,
`sentTime` INT NOT NULL,
`emailType` INT NOT NULL,
PRIMARY KEY (`id`));

ALTER TABLE `tw_ci`.`email_user`
ADD INDEX `fk_email_user_1_idx` (`userId` ASC);
ALTER TABLE `tw_ci`.`email_user`
ADD CONSTRAINT `fk_email_user_1`
FOREIGN KEY (`userId`)
REFERENCES `tw_ci`.`user` (`userId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

CREATE TABLE `tw_ci`.`email_measure` (
`id` INT NOT NULL AUTO_INCREMENT,
`measureId` INT NOT NULL,
`sentTime` INT NOT NULL,
`emailType` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_email_measure_1_idx` (`measureId` ASC),
CONSTRAINT `fk_email_measure_1`
FOREIGN KEY (`measureId`)
REFERENCES `tw_ci`.`measure` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

CREATE TABLE `tw_ci`.`email_watch` (
`id` INT NOT NULL AUTO_INCREMENT,
`watchId` INT NOT NULL,
`sentTime` INT NOT NULL,
`emailType` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_email_watch_1_idx` (`watchId` ASC),
CONSTRAINT `fk_email_watch_1`
FOREIGN KEY (`watchId`)
REFERENCES `tw_ci`.`watch` (`watchId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
2 changes: 1 addition & 1 deletion application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
| $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('url', 'assets', 'language');
$autoload['helper'] = array('url', 'assets', 'language', 'array');

/*
| -------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion application/config/config.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
|
*/

if(isset($_SERVER['HTTP_HOST']) == false){
if (isset($_SERVER['HTTP_HOST']) == false) {
$_SERVER['HTTP_HOST'] = "";
}

Expand Down
71 changes: 55 additions & 16 deletions application/config/constants.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| user, PHP under CGI with Apache suEXEC, etc.). Octal values should
| always be used to set the mode correctly.
|
*/
*/
define('FILE_READ_MODE', 0644);
define('FILE_WRITE_MODE', 0666);
define('DIR_READ_MODE', 0755);
Expand All @@ -26,12 +26,12 @@
|
| These modes are used when working with fopen()/popen()
|
*/
*/

define('FOPEN_READ', 'rb');
define('FOPEN_READ_WRITE', 'r+b');
define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');// truncates existing file data, use with care
define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b');// truncates existing file data, use with care
define('FOPEN_WRITE_CREATE', 'ab');
define('FOPEN_READ_WRITE_CREATE', 'a+b');
define('FOPEN_WRITE_CREATE_STRICT', 'xb');
Expand All @@ -46,7 +46,7 @@
| error_reporting is disabled, the backtrace will not display, regardless
| of this setting
|
*/
*/
define('SHOW_DEBUG_BACKTRACE', TRUE);

/*
Expand All @@ -73,14 +73,53 @@
| Bash scripting:
| http://tldp.org/LDP/abs/html/exitcodes.html
|
*/
define('EXIT_SUCCESS', 0); // no errors
define('EXIT_ERROR', 1); // generic error
define('EXIT_CONFIG', 3); // configuration error
define('EXIT_UNKNOWN_FILE', 4); // file not found
define('EXIT_UNKNOWN_CLASS', 5); // unknown class
define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
define('EXIT_USER_INPUT', 7); // invalid user input
define('EXIT_DATABASE', 8); // database error
define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
*/
define('EXIT_SUCCESS', 0);// no errors
define('EXIT_ERROR', 1);// generic error
define('EXIT_CONFIG', 3);// configuration error
define('EXIT_UNKNOWN_FILE', 4);// file not found
define('EXIT_UNKNOWN_CLASS', 5);// unknown class
define('EXIT_UNKNOWN_METHOD', 6);// unknown class member
define('EXIT_USER_INPUT', 7);// invalid user input
define('EXIT_DATABASE', 8);// database error
define('EXIT__AUTO_MIN', 9);// lowest automatically-assigned error code
define('EXIT__AUTO_MAX', 125);// highest automatically-assigned error code

/*
|--------------------------------------------------------------------------
| Events Status Codes
|--------------------------------------------------------------------------
|
*/
define('CTA_MEASURES', 'CTA_MEASURES');
define('CTA_MEASURE_NOW', 'CTA_MEASURE_NOW');
define('CTA_GET_STARTED', 'CTA_GET_STARTED');
define('CTA_FEATURES', 'CTA_FEATURES');
define('LOGIN_EMAIL', 'LOGIN_EMAIL');
define('LOGIN_FAIL', 'LOGIN_FAIL');
define('LOGIN_FB', 'LOGIN_FB');
define('LOGIN_FB_FAIL', 'LOGIN_FB_FAIL');
define('RESET_PASSWORD', 'RESET_PASSWORD');
define('RESET_PASSWORD_USE', 'RESET_PASSWORD_USE');
define('LOGOUT', 'LOGOUT');
define('SIGN_UP', 'SIGN_UP');
define('SIGN_UP_FAIL', 'SIGN_UP_FAIL');
define('SIGN_UP_FB', 'SIGN_UP_FB');
define('ADD_WATCH', 'ADD_WATCH');
define('ADD_WATCH_LOAD', 'ADD_WATCH_LOAD');
define('DELETE_WATCH', 'DELETE_WATCH');
define('NEW_MEASURE', 'NEW_MEASURE');
define('DELETE_MEASURE', 'DELETE_MEASURE');
define('DELETE_ALL_MEASURES', 'DELETE_ALL_MEASURES');
define('BOARD_LOAD', 'BOARD_LOAD');
define('NEW_ACCURACY', 'NEW_ACCURACY');
define('MEASURE_LOAD', 'MEASURE_LOAD');
define('ACCURACY_LOAD', 'ACCURACY_LOAD');
define('ACCURACY_WARNING_POPUP', 'ACCURACY_WARNING_POPUP');
define('ACCURACY_SOMETHING_WRONG', 'ACCURACY_SOMETHING_WRONG');
define('LOGIN_POPUP', 'LOGIN_POPUP');
define('SIGN_UP_POPUP', 'SIGN_UP_POPUP');
define('HOME_PAGE_0', 'HOME_PAGE_0');
define('HOME_PAGE_1', 'HOME_PAGE_1');
define('HOME_PAGE_2', 'HOME_PAGE_2');
define('HOME_PAGE_3', 'HOME_PAGE_3');
2 changes: 1 addition & 1 deletion application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
$db['default']['password'] = '';
$db['default']['database'] = 'toolwatch';
} else {
$url = parse_url(getenv("TW_DB_URL"));
$url = parse_url('mysql://travis:[email protected]/tw_ci?reconnect=true');
$db['default']['hostname'] = $url["host"];
$db['default']['username'] = $url["user"];
$db['default']['password'] = $url["pass"];
Expand Down
152 changes: 7 additions & 145 deletions application/controllers/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ function login() {
$email = $this->input->post('email');
$password = $this->input->post('password');
if ($this->user->login($email, $password)) {
$this->event->add($this->event->LOGIN_EMAIL);
$result['success'] = true;
} else {
$this->event->add($this->event->LOGIN_FAIL);
$result['success'] = false;
}

Expand Down Expand Up @@ -58,45 +56,13 @@ function facebookSignup() {

if ($this->user->signup($email, $password, $name, $firstname, $timezone, $country)) {

$this->event->add($this->event->SIGN_UP_FB);

$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);
}
$result['success'] = "signup";
$this->user->login($email, $password);

}

} else if ($this->user->login($email, $password)) {

$this->event->add($this->event->LOGIN_FB);

$result['success'] = "signin";

} else {
Expand Down Expand Up @@ -130,47 +96,11 @@ function signup() {
$email, $password, $name, $firstname,
$timezone, $country)) {

$this->event->add($this->event->SIGN_UP);

if ('true' == $mailingList) {
$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);
$result['success'] = true;
$this->user->login($email, $password);

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

$this->event->add($this->event->SIGN_UP_FAIL);

$result['success'] = false;
}
} else {
Expand All @@ -188,42 +118,13 @@ function askResetPassword() {
$email = $this->input->post('email');

$result = array();
$data = array();

$resetToken = $this->user->askResetPassword($email);

if ($resetToken != '') {
$this->event->add($this->event->RESET_PASSWORD);

$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, '');
$this->email->reply_to('[email protected]', 'Toolwatch');
if ($resetToken !== '') {

$this->email->subject('Your Toolwatch password');

$data['resetToken'] = $resetToken;

$message = $this->load->view('email/reset-password', $data, true);
$this->email->message($message);
$result['success'] = true;

if ($this->email->send()) {
$result['success'] = true;
} else {
$result['success'] = false;
}
} else {
$result['success'] = false;
}
Expand All @@ -235,8 +136,6 @@ function askResetPassword() {
function resetPassword() {
if ($this->input->post('resetToken')) {

$this->event->add($this->event->RESET_PASSWORD_USE);

$result = array();

$resetToken = $this->input->post('resetToken');
Expand All @@ -259,8 +158,6 @@ function getReferenceTime() {
function accuracyMeasure() {
if ($this->input->post('measureId')) {

$this->event->add($this->event->NEW_ACCURACY);

$referenceTime = $this->session->userdata('referenceTime');
$userTimezone = $this->input->post('userTimezone');

Expand All @@ -286,7 +183,6 @@ function accuracyMeasure() {

function baseMeasure() {
if ($this->input->post('watchId')) {
$this->event->add($this->event->NEW_MEASURE);

$result = array();

Expand All @@ -302,42 +198,8 @@ function baseMeasure() {

if ($this->measure->addBaseMesure($watchId, $referenceTime, $userTime)) {

$user = $this->user->getUserFromWatchId($watchId);

$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($user->email, $user->name.' '.$user->firstname);
$this->email->reply_to('[email protected]', 'Toolwatch');

$scheduleTime = time()+86400;
$sentAt = date('Y-', $scheduleTime).date('m-', $scheduleTime).(date('d', $scheduleTime)).' '.(date('H', $scheduleTime)-1).':'.(date('i', $scheduleTime)).date(':s', $scheduleTime);
$this->email->set_header('X-MC-SendAt', $sentAt);

$this->email->subject('It\'s time to check your watch\'s accuracy !');

$data['watchBrand'] = $user->brand;
$data['watchName'] = $user->name;

$message = $this->load->view('email/remind-check-accuracy', $data, true);
$this->email->message($message);
$result['success'] = true;

if ($this->email->send()) {
$result['success'] = true;
} else {
$result['success'] = false;
}
} else {
$result['success'] = false;
}
Expand Down
Loading

0 comments on commit 02776fb

Please sign in to comment.