Unable to get User's age, city, country, just able to get display name, email and gender - hybridauth

I'm using hybridauth for login into my website. The below code just gives me display name, gender and email not any other else. but i want to get other information also like age, city, country.
Note: getting information from my own facebook profile, which from i got api key and secret. also i set my all information Public.
In hybridauth, i've used scope for facebook as below,
"scope" => "email,user_gender, user_friends, user_birthday, user_age_range, user_hometown, user_link, user_location",
and get information by,
<?php
/**
* Build a simple HTML page with multiple providers.
*/
include '../hybridauth/src/autoload.php';
include 'config.php';
use Hybridauth\Hybridauth;
$hybridauth = new Hybridauth($config);
$adapters = $hybridauth->getConnectedAdapters();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example 06</title>
</head>
<body>
<h1>Sign in</h1>
<ul>
<?php foreach ($hybridauth->getProviders() as $name) : ?>
<?php if (!isset($adapters[$name])) : ?>
<li>
<a href="<?php print $config['callback'] . "?provider={$name}"; ?>">
Sign in with <strong><?php print $name; ?></strong>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php if ($adapters) : ?>
<h1>You are logged in:</h1>
<ul>
<?php foreach ($adapters as $name => $adapter) : ?>
<li>
<strong><?php print $adapter->getUserProfile()->displayName." email: ".$adapter->getUserProfile()->email.
" gender: ".$adapter->getUserProfile()->gender.
" age: ".$adapter->getUserProfile()->age. " city: ".$adapter->getUserProfile()->city ." country: ".$adapter->getUserProfile()->country." unique id: ".$adapter->getUserProfile()->identifier; ?></strong> from
<i><?php print $name; ?></i>
<span>(Log Out)</span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</body>
</html>
but above code just gives display name, gender and email and not any else.

Related

How to send link/url to confirm user registration and/or password reset/recovery using ASP.Net MVC2?

I see it all over the place, yet, I could not find one example about this (maybe I don't know the proper wording), I am trying to build using ASP .Net MVC2 (but any example on just ASP .Net would be also helpful) a process that will send a link to the user at the end of the registration process to let him confirm his registration. Also, a similar process to let the user to reset his password, with the typical "forgot password" and send a link/url so that the user can click and type a new password. Can someone help me to either find an example or at least to let me know how to "google" it?
Thanks,
Mark
For the forgot password, you can make a view like this
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true)%>
<p><%: ViewData["Error"] %></p>
<p> Have you forgotten you password? No problem!</p>
<div class="editor-label">
<%: Html.Label("Fill in your username") %>
</div>
<div class="editor-field">
<%: Html.TextBox("userName") %>
</div>
<p> and <input type="submit" value="click here" /> to reset your password.</p>
<% } %>
and as a controller (first make an model from the aspnetdb (if you don't see it press the 'show all files' button))
This must be placed right after the controller definition
aspnetdbEntities aspnetdb = new aspnetdbEntities();
Then follows this
public ActionResult ForgottenPassword()
{
return View();
}
[HttpPost]
public ActionResult ForgottenPassword(FormCollection formValue)
{
var userName = formValue["userName"];
try
{
var useraccount = aspnetdb.aspnet_Users.Single(c => c.UserName == userName);
var fromAddress = "put an email-address";
var message = new MailMessage(fromAddress, user.Email)
{
Subject = "",
Body = "a link to a controller that lets the user put in a
new password and then save that password to the aspnetdb."
(that controller will most likley require a username)
"or a link with a new random password in it tht you have put
as his password like this:"
useraccount.aspnet_Membership.Password = "random password";
aspnetdb.SaveChanges;
};
var client = new SmtpClient("smtpServerName");
client.Send(message);
return View();
}
catch
{
ViewData["Error"] = "Please give up an existing username";
return View();
}
}
I hope this answer was helpfull.

Send Email & Create Order programmatically on Product page with Custom form

When customer enters the details in the form fields and enter submit button then the Order email should send customer's email immediately and also Order should be created in Backend as well. Once its submitted(After email sent & order created), the success message will display on same current product page.
For this, I haved added my Custom order form on my theme's product detailed page. Form contains the fields like Name, Email, Quantity, Product Name and Price(Current Product Name & Price when customer Visits).
How to send email and create order programmatically on Product page custom form?
Any help mostly appreciated.
You would need to create a block class for your template ( there are many resources on how to create a controller for Magento 2, you can reference them).
There you can have a method that gets the product URL for adding the order:
public function getAddProductUrl($product, $additional = [])
{
return $this->_cartHelper->getAddUrl($product, $additional);
}
Then in your phtml template file add the following html form and javascript or somethng similar to this:
<script type="text/x-magento-init">
{
"[data-role=tocart-form]": {
"catalogAddToCart": {}
}
}
</script>
<div class="product-add-form">
<?php $product = $block->getProduct(); ?>
<form data-product-sku="<?= /* #NoEscape */ $product->getSku() ?>"
action="<?= /* #NoEscape */ $block->getAddProductUrl($product) ?>" method="post" data-role="tocart-form">
<input type="hidden" name="product" value="<?= /* #escapeNotVerified */ $product->getId() ?>" />
<?= $block->getBlockHtml('formkey') ?>
<button type="submit" title="<?php echo /* #escapeNotVerified */ __('Add to Cart'); ?>" class="action primary tocart">
<span><?php echo /* #escapeNotVerified */ __('Add to Cart'); ?></span>
</button>
</form>
</div>

Show binary data uisng codeigniter

We are trying to do a MLM binary structure using CodeIgniter. But unable to do that. If someone help me then i will be glad. I have given the database image, Binary Tree Image, and also all the required code. just check and tell me how can I put the values in binary tree in a correct format. I want to show only 3 layer like the image after that we don't need more layer. The main Parent node is the user code of the logged in user. Hope you understand my point.
Image of Binary Tree
View Code
<div class="tree">
<ul>
<li>
001
<ul>
<li>
002
<ul>
<li>
004
<ul>
<li>008</li>
<li>009</li>
</ul>
</li>
<li>005
<ul>
<li>010</li>
<li>010</li>
</ul></li>
</ul>
</li>
<li>
003
<ul>
<li>006
<ul>
<li>012</li>
<li>013</li>
</ul></li>
<li>007
<ul>
<li>014</li>
<li>015</li>
</ul></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Model Code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class TreeModel extends CI_Model {
public function get_parent_node()
{
$this->load->database();
$query = $this->db->select('ref_code')
->group_by('ref_code')
->get('tbl_tree');
$result = $query->result_array();
return $result;
}
public function get_child_node($parent_node)
{
$this->load->database();
$query = $this->db->where('ref_code', $parent_node)
->get('tbl_tree');
$result = $query->result_array();
return $result;
}
}
Controller Code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->model('TreeModel');
$parent_node = $this->TreeModel->get_parent_node();
$complete_tree = array();
foreach($parent_node as $parent):
$child_node = $this->TreeModel->get_child_node($parent['ref_code']);
$parent['childs'] = $child_node;
foreach($child_node as $child):
$child_node_1 = $this->TreeModel->get_child_node($child['ref_code']);
$parent['childs_1'][] = $child_node_1;
endforeach;
array_push($complete_tree, $parent);
endforeach;
echo "<pre>";
print_r($complete_tree);
die();
$data['tree'] = $complete_tree;
$this->load->view('welcome_message', $data);
}
}
Thanks in advance.

grails controllers render errors multiple domain classes

I have this controller which performs me a multiple domain databinding class, and it is working as i want. But i would like some help about the error messages. Is it possible to display error messages from multiple domain classes? If so, how should be the code both is the view and in the controller?
class CarroMovel {
String move
String rodas
String espelhos
Carro carro
static hasMany = [carros: Carro]
static belongsTo = Carro
static constraints = {
move(nullable:false, blank:false)
}
static mapping = {
version false
}
}
class Carro {
String name
String marca
String matricula
static constraints = {
name(nullable:false, blank:false)
}
static mapping = {
version false
}
}
def save3 = {
def carroInstance = new Carro( )
def carroMovelInstance = new CarroMovel( )
carroInstance.name = params.carro.name
carroInstance.marca = params.carro.marca
carroInstance.matricula = params.carro.matricula
carroMovelInstance.move = params.carroMovel.move
carroMovelInstance.rodas = params.carroMovel.rodas
carroMovelInstance.espelhos = params.carroMovel.espelhos
carroInstance.save(failOnError: true)
carroMovelInstance.carro = carroInstance
carroMovelInstance.save(failOnError: true)
}
<g:form controller="carro" action="save3">
<h1>Add New Carro Record</h1>
<p>Basic Information</p>
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="carro.name" value="${carroInstance?.name}" /><br>
<label>Marca
<span class="small">Add your name</span>
</label>
<input type="text" name="carro.marca" value="${carroInstance?.marca}" /><br
<label>Matricula
<span class="small">Add your name</span>
</label>
<input type="text" name="carro.matricula" value="${carroInstance?.matricula}" /><br>
<label>Move
<span class="small">Add your name</span>
</label>
<input type="text" name="carroMovel.move" value="${carroMovelInstance?.move}" /><br>
<label>Rodas
<span class="small">Add your name</span>
</label>
<input type="text" name="carroMovel.rodas" value="${carroMovelInstance?.rodas}" /><br>
<label>Espelho
<span class="small">Add your name</span>
</label>
<input type="text" name="carroMovel.espelhos" value="${carroMovelInstance?.espelho}" /><br>
<g:submitButton name="save" value="Save" id="addConference"/>
<div class="spacer"></div>
</g:form>
<g:hasErrors bean="${carroInstance}">
<div class="errors">
<g:renderErrors bean="${carroInstance}" as="list" />
</div>
</g:hasErrors>
Grails Validation Errors Primer
The errors for a domain object are stored in an errors property that is added to the object after it is validated. This property is an implementation of the Spring Errors interface.
You can get the errors either by calling the methods of this interface directly, e.g. to display the errors for the move field of a Carro instance:
List<FieldError> moveErrors = carroMovelInstance.errors?.getFieldErrors('move')
To get the error messages for each error, you'll need a referrence to the messageSource bean created by Grails. You could get the message for each of the above errors with:
List<String> errorMessages = moveErrors.collect {error ->
messageSource.getMessage(error, Locale.default)
}
Alternatively, Grails provides the eachError and renderErrors tags that simplify displaying errors and their corresponding messages in a GSP.
Specific Problems With Your Code
In your controller code, an exception will be thrown whenever save fails due to validation errors, so the view has no opportunity to display the errors. To fix this, change the controller so that it returns the domain objects (along with their errors) when saving fails
def save3 = {
def carroInstance = new Carro( )
def carroMovelInstance = new CarroMovel( )
carroInstance.name = params.carro.name
carroInstance.marca = params.carro.marca
carroInstance.matricula = params.carro.matricula
carroMovelInstance.move = params.carroMovel.move
carroMovelInstance.rodas = params.carroMovel.rodas
carroMovelInstance.espelhos = params.carroMovel.espelhos
// I'm assuming in the code below that the view that displays the form is 'create.gsp'
if (!carroInstance.save()) {
render view: 'create', model : [carro: carroInstance, carroMovel: carroMovelInstance]
return
}
carroMovelInstance.carro = carroInstance
if (!carroMovelInstance.save()) {
render view: 'create', model : [carro: carroInstance, carroMovel: carroMovelInstance]
}
}
The GSP also needs to be changed to display these errors using either the Errors API directly or one of the Grails tags (see above)

How can I pass FORM on a button click in MVC2.0?

I am calling a controller method SendMe(formCollection myForm){}.
But I don't know how to pass Form that contains some information. I know how to read it, and also, how to call SendMe() on given controller, but I don't know how to pass it. Though, for the reference I am calling SendMe as:
<div id="menucontainer">
<ul id="menu">
<li><%: Html.ActionLink("Send", "SendMe", "Mail")%></li>
</ul>
</div>
and my SendMe method is:
public ActionResult SendMe(FormCollection Form)
{
string From = Form["From"].ToString();
string Pass = Form["Password"].ToString();
string To = Form["To"].ToString();
string Subject = Form["Subject"].ToString();
string Message = Form["Message"].ToString();
MailMessage nmsg = new MailMessage(From, To, Subject, Message);
nmsg.IsBodyHtml = true;
nmsg.Priority = MailPriority.High;
SmtpClient smtpc = new SmtpClient("smtp.gmail.com", 587);
smtpc.Credentials = new System.Net.NetworkCredential(From, Pass);
smtpc.EnableSsl = true;
smtpc.Send(nmsg);
return View();
}
I haven't put anything in Model, though, MailController and SendMe.aspx are in place.
tell me how to get through this. Thanks in advance.
This simple code should work...if all you need is this to submit information from a form...Please clear if i understood it wrong..I would recommend using a viewmodel or something though to have validation for those fields...and in viewmodel case you should inherit the page from the viewmodel...and retrieve from the viewmodel object instead of formcollection...
<% Html.BeginForm("SendMe", "Send", FormMethod.Post); %> //Here 1st parameter is the actionname while second is the Controller name
//Form Fields....
<input id="SendMe" type="submit" value="Send Info" />
<% Html.EndForm(); %>
In order to obtain the FORM variables in your controller, the form needs to be submitted via a Http POST.
<% using (Html.BeginForm()) {%>
.....
<% Html.EndForm(); %>

Resources