Skip to content

Instantly share code, notes, and snippets.

@walterheck
Created April 26, 2016 20:20
Show Gist options
  • Save walterheck/8d4f3cf38d2730dc9d7c958db8378fb5 to your computer and use it in GitHub Desktop.
Save walterheck/8d4f3cf38d2730dc9d7c958db8378fb5 to your computer and use it in GitHub Desktop.
<<<<<<< 327d88f5e6ba7c20ea0103f1f02d2bfb54a9b52f
public function updatedeviceinfoAction() {
if ($user = $this->checkAuth()) {
extract($this->getRequest()->getPost());
$device_token = $this->_getParam('device_token');
$device_type = $this->_getParam('device_type');
if (empty($device_token)) {
$this->JSONErrorOutput('device token required');
}
if (empty($device_type)) {
$this->JSONErrorOutput('device type required');
}
$device_table = Engine_Api::_()->getDbtable('pushdevices', 'rvapi');
$db = $device_table->getAdapter();
$db->beginTransaction();
try {
require __DIR__ . '/../externals/aws/aws-autoloader.php';
require __DIR__ . '/../../../../vendor/autoload.php';
// Hardcoded credentials.
$client = new Aws\Sns\SnsClient([
'version' => 'latest',
'region' => $this->_AWS_region,
'credentials' => [
'key' => $this->_AWS_key,
'secret' => $this->_AWS_secret
]
]);
$select = $device_table->select()
->where('device_token = ?', $device_token);
$registeredDevice = $device_table->fetchRow($select);
if (!$registeredDevice) { // for first time entry
$this->createDeviceinfo($client, $device_table, $user);
} else { // user with same device ID
// get the enpoint arn
$endpointArn = $registeredDevice->end_point_arn;
try {
$endpointAtt = $client->getEndpointAttributes([
'EndpointArn' => $endpointArn, // REQUIRED
]);
if ($endpointAtt == true) {
$client->setEndpointAttributes(array(
'Attributes' => ['Enabled' => TRUE], // REQUIRED
'EndpointArn' => $endpointArn, // REQUIRED
));
}
$registeredDevice->user_id = $user->getIdentity();
$registeredDevice->device_type = $device_type;
$registeredDevice->device_token = strip_tags(trim($device_token));
$registeredDevice->updated_on = date("Y-m-d H:i:s");
$registeredDevice->save();
} catch (Exception $exc) {
// DELETE FROM OUR DATABASE
$registeredDevice->delete();
$this->createDeviceinfo($client, $device_table, $user);
}
}
$db->commit();
$response['response']['success'] = 'update successful';
$this->JSONSuccessOutput($response);
} catch (Exception $e) {
$db->rollBack();
$this->JSONErrorOutput('An error occur.');
=======
public function forgotPasswordAction() {
extract($this->getRequest()->getPost());
if (empty($email)) {
$this->JSONErrorOutput('email address required');
}
// Check for existing user
$user = Engine_Api::_()->getDbtable('users', 'user')
->fetchRow(array('email = ?' => $email));
if (!$user || !$user->getIdentity()) {
$this->JSONErrorOutput('A user account with that email was not found.');
}
// Check to make sure they're enabled
if (!$user->enabled) {
$this->JSONErrorOutput('That user account has not yet been verified or disabled by an admin.');
}
// Ok now we can do the fun stuff
$forgotTable = Engine_Api::_()->getDbtable('forgot', 'user');
$db = $forgotTable->getAdapter();
$db->beginTransaction();
try {
// Delete any existing reset password codes
$forgotTable->delete(array(
'user_id = ?' => $user->getIdentity(),
));
// Create a new reset password code
$code = base_convert(md5($user->salt . $user->email . $user->user_id . uniqid(time(), true)), 16, 36);
$forgotTable->insert(array(
'user_id' => $user->getIdentity(),
'code' => $code,
'creation_date' => date('Y-m-d H:i:s'),
));
// Send user an email
Engine_Api::_()->getApi('mail', 'core')->sendSystem($user, 'core_lostpassword', array(
'host' => $_SERVER['HTTP_HOST'],
'email' => $user->email,
'date' => time(),
'recipient_title' => $user->getTitle(),
'recipient_link' => $user->getHref(),
'recipient_photo' => $user->getPhotoUrl('thumb.icon'),
'object_link' => $this->view->url(array('module' => 'user', 'controller' => 'auth', 'action' => 'reset', 'code' => $code, 'uid' => $user->getIdentity()), 'default', true),
'queue' => false,
));
$db->commit();
// Show success
$response['response']['success'] = 'success';
$response['response']['msg'] = $this->view->translate('USER_VIEWS_SCRIPTS_AUTH_FORGOT_DESCRIPTION');
$this->JSONSuccessOutput($response);
} catch (Exception $e) {
$db->rollBack();
$this->JSONErrorOutput('Some error occured try again');
}
}
public function updatedeviceinfoAction() {
if ($user = $this->checkAuth()) {
extract($this->getRequest()->getPost());
if (empty($device_token)) {
$this->JSONErrorOutput('device token required');
}
//echo $device_type; exit;
$device_table = Engine_Api::_()->getDbtable('devices', 'rvapi');
$db = $device_table->getAdapter();
$db->beginTransaction();
try {
$select = $device_table->select()
->where('user_id = ?', $user->getIdentity())
;
$registeredDevice = $device_table->fetchRow($select);
if ($registeredDevice->device_id) {
$registeredDevice->device_type = 1;
$registeredDevice->device_token = strip_tags(trim($device_token));
$registeredDevice->save();
} else {
$device = $device_table->createRow();
$device->user_id = $user->getIdentity();
$device->device_type = 1;
$device->device_token = strip_tags(trim($device_token));
$device->save();
}
$db->commit();
$response['response']['success'] = $this->view->translate('update successful', $this->lang);
$this->JSONSuccessOutput($response);
} catch (Exception $e) {
$db->rollBack();
// throw $e;
$this->JSONErrorOutput('An error has occurred.');
>>>>>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment