everyone I am new here.
I stuck with Magento API.I am creating Magento API for my e-commerece site.I have created all API but for forget password API I am not getting any solution. I have used default forget password controller but it didn't send me an email with change password link check my code and please help me to set this forget password API.I have also search all the documents but getting any answer. I have also post my code so please refer it and let me know that where is I have mistake.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$email = $_REQUEST['email'];
require_once ('../app/Mage.php');
Mage::app();
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($email);
//print_r($customer);
if ($customer->getId()) {
try {
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->setStoreId(Mage::app()->getStore()->getId());
$customer->sendPasswordResetConfirmationEmail();
$response['response'] = "success";
$response['message']="Password Reset Link Has Been Sent to Your Email Please Check, Your Mail Box!";
echo json_encode($response);
} catch (Exception $exception) {
Mage::log($exception);
}
}else{
$response['response'] = "failed";
$response['message']="Please Enter a Valid Email!";
echo json_encode($response);
}
?>
Recently i worked on forget password magento api it work fine but only difficult i find that i have to save my forget password file name to index.php. make one api folder and save it with name of index.php
<?php
if(!empty($_REQUEST['email']))
{
$yourCustomerEmail=$postcode = $_REQUEST['email'];
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($yourCustomerEmail);
//echo $customer->getId();
if ($customer->getId()) {
try {
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->sendPasswordResetConfirmationEmail();
$result = array('action'=> 'send','statuscode'=> '200');
echo json_encode($result);
} catch (Exception $exception) {
//echo "Exception";
Mage::log($exception);
}
}
else
{
$result = array('action'=> 'failed','statuscode'=> '300');
echo json_encode($result);
}
}
else
{
$result = array('action'=> 'failed','statuscode'=> '300');
echo json_encode($result);
}
?>
Related
I'm new to php and I'm trying to work out how to send myself an email upon successful payment. How would I go about that? If you see half way down the script there is an 'if' statement that defines a successful Stripe Payment Call - so that is the point where an email ought to be sent.
Do I include a POST Email request - like this:
($_POST['email'])) {
$email_to = "me#example.com";
$email_subject = "Email subject line";
And here's the php script that currently works - you'll see the 'IF' statement half way throught the script.
<?php
require('config.inc.php');
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email=$_POST['email'];
// Stores errors:
$errors = array();
// Need a payment token:
if (isset($_POST['stripeToken'])) {
$token = $_POST['stripeToken'];
// Check for a duplicate submission, just in case:
// Uses sessions, you could use a cookie instead.
if (isset($_SESSION['token']) && ($_SESSION['token'] == $token)) {
$errors['token'] = 'You have apparently resubmitted the form.';
} else { // New submission.
$_SESSION['token'] = $token;
}
} else {
$errors['token'] = 'Your subscription cannot be processed because you must have JavaScript enabled. Please try again.';
}
// Set the order amount somehow:
$amount = 2700; // $20, in cents
// Validate other form data!
// If no errors, process the order:
if (empty($errors)) {
// create the charge on Stripe's servers - this will charge the user's card
try {
// Include the Stripe library:
require_once('lib/Stripe.php');
// set your secret key: remember to change this to your live secret key in production
// see your keys here https://manage.stripe.com/account
Stripe::setApiKey(STRIPE_PRIVATE_KEY);
// Charge the order:
$charge=Stripe_Customer::create(array(
"card"=>$token,
"email" => $email,
"plan" =>"newsletter",
));
// Check that it was paid:
if (!empty($charge)) {
//echo $amount;
// Store the order in the database.
// Send the email.
// Celebrate!
/*$cookie_name = "success_msg";
$cookie_value = "Your Payment is successfully done";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");*/
$_SESSION['success_msg']="Your subcription was successfull - thank you!<br><br>We will send you further details shortly on how to access your account.";
echo "<script>window.location.href='index.php'</script>";
exit(0);
} else { // Charge was not paid!
echo '<div class="alert alert-error"><h4>Payment System Error!</h4>Your payment could NOT be processed (i.e., you have not been charged) because the payment system rejected the transaction. You can try again or use another card.</div>';
}
} catch (Stripe_CardError $e) {
// Card was declined.
$e_json = $e->getJsonBody();
$err = $e_json['error'];
$errors['stripe'] = $err['message'];
} catch (Stripe_ApiConnectionError $e) {
// Network problem, perhaps try again.
} catch (Stripe_InvalidRequestError $e) {
// You screwed up in your programming. Shouldn't happen!
} catch (Stripe_ApiError $e) {
// Stripe's servers are down!
} catch (Stripe_CardError $e) {
// Something else that's not the customer's fault.
}
} // A user form submission error occurred, handled below.
} // Form submission.
?>
asdasd
You could create a function that sends the email:
function sendEmail () {
$email_to = "me#example.com";
$email_subject = "Email subject line";
... ETC ...
}
Then in your script where the payment is successful, just before notifying the user you can include the function:
...
if (!empty($charge)) {
...
// Include your function if you wrote this to an external script
require_once '/path/to/php/sendEmail.function.php';
// Then make use of it:
sendEmail();
/*$cookie_name = "success_msg";
$cookie_value = "Your Payment is successfully done";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");*/
$_SESSION['success_msg']="Your subcription was successfull - thank you!<br><br>We will send you further details shortly on how to access your account.";
// Redirect the user to a new page
echo "<script>window.location.href='index.php'</script>";
// Then you can exit runtime
exit(0);
}
// Charge was not paid!
else {
echo '<div class="alert alert-error"><h4>Payment System Error!</h4>Your payment could NOT be processed (i.e., you have not been charged) because the payment system rejected the transaction. You can try again or use another card.</div>';
}
...
It's pretty important that the email function will either send the email or just continue as normal as you'd not want a failed email to interupt the users experience. You could have a fallback so that if the email doesnt send it writes it to the database or something but do not exit with an error during this process.
for a project I am currently working on I am using rabbitMQ to queue tasks, and send messages. If I run the server and the client from a terminal I will receive data, but if I try to include the php in an index.php that tries to display the into to a web page it does not work. What am I doing wrong, I tried wrapping the testRabbitMQClient.php in a function but this still does not work.What am I missing?
<?php
//index.php
require 'openid.php';
require 'functions.php';
require 'testRabbitMQClient.php';
/*
#connects to my database and checks to make sure its connected.
*/
$apikey="key";
try {
$openid = new LightOpenID('localhost');
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'http://steamcommunity.com/openid';
header('Location: ' . $openid->authUrl());
}
?>
<h1>Hey ____ thank you for using FOF.com</h1>
<br>
<?php
//showFriends(xxxxxxxxxxxxxxxxx);
//calls function from testRabbitMQClient.php
send("friends");
?>
<form action="?login" method="post">
<input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png">
</form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
if($openid->validate()) {
$id = $openid->identity;
// identity is something like: http://steamcommunity.com/openid/id/76561197994761333
// we only care about the unique account ID at the end of the URL.
$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
echo "User is logged in (steamID: $matches[1])\n";
}
else
{
echo "User is not logged in.\n";
}
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
?>
#!/usr/bin/php
<?php
//rabbit mq client;
require_once('path.inc');
require_once('get_host_info.inc');
require_once('rabbitMQLib.inc');
function send($type){
$client = new rabbitMQClient("testRabbitMQ.ini","testServer");
if (isset($argv[1]))
{
$msg = $argv[1];
}
else
{
$msg = "test message";
}
$request = array();
$request['type'] = "friends";
$request['username'] = "steve";
$request['password'] = "password";
$request['message'] = $msg;
$response = $client->send_request($request);
//$response = $client->publish($request);
echo "client received response: ".PHP_EOL;
echo $response;
echo "\n\n";
echo $argv[0]." END".PHP_EOL;
}
?>
I figured out my issue! I forgot to enable amqp in apache. I did this by adding the extension=amqp.so to the php.ini file that is located in the apache folder.
I have big problem because, when I'm trying to show status of my ts3 server I have blank page... What am I doing wrong?
require_once('libraries/TeamSpeak3/TeamSpeak3.php');
try
{
// connect to server, authenticate and grab info
$ts3 = TeamSpeak3::factory("serverquery://query_admin:query_pass#host:10011/?server_port=9987");
// show server as online
$serverinfo[$j]['hostname'] = $ts3->virtualserver_name;
$serverinfo[$j]['online'] = 'online';
$serverinfo[$j]['players'] = $ts3->virtualserver_clientsonline;
$serverinfo[$j]['max'] = $ts3->virtualserver_maxclients;
}
catch(Exception $e)
{
// grab errors and show server as offline
$serverinfo[$j]['online'] = 'offline';
$serverinfo[$j]['players'] = '-';
$serverinfo[$j]['max'] = '-';
}
When I comment this code the page shows as normal...
EDIT:
I see it now, if I only add this
require_once('libraries/TeamSpeak3/TeamSpeak3.php');
and nothing more to my code it shows blank page... Is it possible, that library from here doesn't work properly?
You forgot to add echo before each info so the code becomes :
require_once('libraries/TeamSpeak3/TeamSpeak3.php');
try
{
// connect to server, authenticate and grab info
$ts3 = TeamSpeak3::factory("serverquery://query_admin:query_pass#host:10011/?server_port=9987");
// show server as online
echo $serverinfo[$j]['hostname'] = $ts3->virtualserver_name;
echo $serverinfo[$j]['online'] = 'online';
echo $serverinfo[$j]['players'] = $ts3->virtualserver_clientsonline;
echo $serverinfo[$j]['max'] = $ts3->virtualserver_maxclients;
}
catch(Exception $e)
{
// grab errors and show server as offline
echo $serverinfo[$j]['online'] = 'offline';
echo $serverinfo[$j]['players'] = '-';
echo $serverinfo[$j]['max'] = '-';
}
I have a form where the user can enter their credit information. When they submit I keep getting 'Object not found'.
I checked the keys and subdomain everything is correct. What could be the issue?
public function createSubscription($plan,$token,$email,$fname,$lname,$currency,$starts_at,$company_name)
{
try {
$subscription = new \Recurly_Subscription();
$subscription->plan_code = $plan;
$subscription->currency = $currency;
$subscription->starts_at = $starts_at;
$account = new \Recurly_Account();
$account->account_code = $email;
$account->first_name = $fname;
$account->last_name = $lname;
$account->email = $email;
$account->company_name = $company_name;
$billing_info = new \Recurly_BillingInfo();
$billing_info->token_id = $token;
$account->billing_info = $billing_info;
$subscription->account = $account;
$subscription->create();
}
catch (\Recurly_ValidationError $e){
throw new CreditDeclined($e->getMessage());
}
catch ( \Exception $e) {
throw new InvalidGeneral($e->getMessage());
}
}
The two things I'd check first are that the plan code and billing token are valid.
The other thing to check is that you've loaded our PHP libraries. You need to have this someplace in your code:
require_once('lib/recurly.php');
Require the lib/recurly.php script and setup your authentication credentials:
<?php
require_once('lib/recurly.php');
// Required for the API
Recurly_Client::$subdomain = 'your-subdomain';
Recurly_Client::$apiKey = 'abcdef01234567890abcdef01234567890';
?>
It should be correct.Please re-check.
I have a website running on a less well known CMS called Ushahidi. There is built in OpenID functionality where folk can login with Facebook or Google.
I don't have enough dev skills to understand whats happening here but, it appears that I've almost got it working, except, I'm receiving the following error when trying to test it out on my own Google login:
An error was detected which prevented the loading of this page. If
this problem persists, please contact the website administrator.
application/controllers/login.php [503]: Undefined variable: user
I suspect, but am not sure, that defining a variable is easy enough but since I lack the knowledge I hoped to ask someone on here if they could see where I need to define the variable. Line 503 is part of a larger code block of about 100 lines, I know that it's not good practice to post larger chunks of code on here but I'm really unsure of what is and is not relevant. So forgive me. I have highlighted in bold where line 503 is. Can anyone point out what I must do here?
// OpenID Post
try
{
$openid = new OpenID;
// Retrieve the Name (if available) and Email
$openid->required = array("namePerson", "contact/email");
if( ! $openid->mode)
{
if(isset($_POST["openid_identifier"]))
{
$openid->identity = $_POST["openid_identifier"];
header("Location: " . $openid->authUrl());
}
}
elseif ($openid->mode == "cancel")
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = "You have canceled authentication!";
}
else
{
if ($openid->validate())
{
// Does User Exist?
$openid_user = ORM::factory("openid")
->where("openid", $openid->identity)
->find();
if ($openid_user->loaded AND $openid_user->user)
{
// First log all other sessions out
$auth->logout();
// Initiate Ushahidi side login + AutoLogin
$auth->force_login($openid_user->user->username);
// Exists Redirect to Dashboard
**(THIS IS LINE 503)** url::redirect($user->dashboard());
}
else
{
// Does this openid have the required email??
$new_openid = $openid->getAttributes();
if ( ! isset($new_openid["contact/email"]) OR
empty($new_openid["contact/email"]))
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $openid->identity . " has not been logged in. No Email Address Found.";
}
else
{
// Create new User and save OpenID
$user = ORM::factory("user");
// But first... does this email address already exist
// in the system?
if ($user->email_exists($new_openid["contact/email"]))
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $new_openid["contact/email"] . " is already registered in our system.";
}
else
{
$username = "user".time(); // Random User Name from TimeStamp - can be changed later
$password = text::random("alnum", 16); // Create Random Strong Password
// Name Available?
$user->name = (isset($new_openid["namePerson"]) AND ! empty($new_openid["namePerson"]))
? $new_openid["namePerson"]
: $username;
$user->username = $username;
$user->password = $password;
$user->email = $new_openid["contact/email"];
// Add New Roles
$user->add(ORM::factory('role', 'login'));
$user->add(ORM::factory('role', 'member'));
$user->save();
// Save OpenID and Association
$openid_user->user_id = $user->id;
$openid_user->openid = $openid->identity;
$openid_user->openid_email = $new_openid["contact/email"];
$openid_user->openid_server = $openid->server;
$openid_user->openid_date = date("Y-m-d H:i:s");
$openid_user->save();
// Initiate Ushahidi side login + AutoLogin
$auth->login($username, $password, TRUE);
// Redirect to Dashboard
url::redirect($user->dashboard());
}
}
}
}
else
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $openid->identity . "has not been logged in.";
}
}
}
catch (ErrorException $e)
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $e->getMessage();
}
The problem is that the code is using $user several lines before it's actually defined. It might be a typo, though - maybe $openid_user->user->dashboard() at line 503 might work, though it's a WAG.