how to create signup form in sugarcrm? - sugarcrm

I want to create signup page in SugarCRM. after entering their details in the signup page all details have to insert in the SugarCRM database.
I written signup form using PHP but I don't know how to integrate it with SugarCRM. Kindly help me.
Tried Campaigns module but no use of this for my requirement.

Based on your question and comment, I understand that you want to have a web form that creates users in your SugarCRM system. This can be mostly done using the API, although the API doesn't seem to handle user passwords very well. I would approach it this way:
<?php
// leverage Asa Kusuma's excellent SugarCRM API Wrapper for PHP
$sugar = new \Asakusuma\SugarWrapper\Rest;
$sugar->setUrl('https://my.sugarsystem.com/service/v2/rest.php');
$sugar->setUsername('admin'); // ensure this user has the ability to create and manage users
$sugar->setPassword('password');
$sugar->connect();
$user_data = array(
'user_name' => 'Sharmila',
'first_name' => 'Sharmila',
'last_name' => 'Smith',
'email1' => 'ssmith#whatever.com',
'is_admin' => '0',
'status' => 'Active',
'employee_status' => 'Active',
);
$new_user_id = $sugar->set('Users',$user_data);
You'll then need a mechanism to email this new user a link to the login page with instructions to click "Forgot Password?" and have a password re-set for them. They will not be able to log in until they've reset their password. Alternatively, you could create a logic hook or API extension to save the password via this API call or another one.

Related

Laravel makeshift SSO approach

We want to implement a SSO like approach in our program where users will register in a third party program and synchronously register in our program and authenticate the login/logout from the third party. Since we don't have access to the third party's authentication. The 3rd party program is our client's program that wants to use our program's services.
Since packages like miniorage is not free, we need to do this the hard way.
Here is what I have done and will try finish:
Already done code:
Install laravel/passport in our program.
Create an registration API that the client in third party can use to register in our program
With passport, it will return a Bearer token that they need to save in their system (Remove the expi`ration date)
Create a URL that will accept the bearer token that was created during the registration
When the URL is opened, I will be able to use the Auth::user() and get user info.
Trying to accomplish:
$credentials = ([
'email' => 'test#gmail.com',
]);
if (Auth::attempt($credentials)) {
Log::info(Auth::user());
}
From the Auth::user(), get the email address and re-login using the code above
However, when I open another page, the Auth::user() is empty.
My question is:
1 Is this approach okay for a makeshift SSO?
2 Why is the Auth::user() empty on a different url even if I manually login the user?
UPDATE
So I think I will continue with the Laravel Passport as a makeshift SSO on our program. However I want to do a Auth::login() when I pass the token in the header:
Here would be the code:
public function authenticate()
{
$user = Auth::user();
Log::info($user);
. . . . . .
$authuser = User::where('email', '=', $user->email)->first();
$authuser = Auth::login($authuser);
Log::info($authuser);
return $user;
}
The reason why I wish to use Auth::Login here is so that the user is authenticated on all pages. Not just in the first page.
The function authenticate is used when I access the program with the Bearer Token. In the $authuser part, I want to re login the user with just the email. Reason why only email is because of the logic before this. Yes we already consider this one. However when I use the Auth::login($authuser);, it returns Method Illuminate\Auth\RequestGuard::login does not exist error message.
Possible data that you wish to see:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
],
api => driver was originally token before the laravel passport was implemented
Is this approach okay for a makeshift SSO?
It might work with Passport, but it's not really the intended use (OAuth2) for it. I found it more confusing than just rolling out a custom solution:
Install JWT auth - https://jwt-auth.readthedocs.io/en/develop/laravel-installation/
Set guard in config/auth.php
I'd look into using a manual JWT auth solution (https://jwt-auth.readthedocs.io/en/develop/laravel-installation/)
2 Why is the Auth::user() empty on a different url even if I manually login the user?
Most likely because the route/controller method is missing an auth middleware that says it's an authenticated.
After trial and errors, I decided to use Laravel Passport and fixed the Auth::login not persisting. For the Auth::login issue, I moved \Illuminate\Session\Middleware\StartSession::class, from $middlewareGroups to $middleware

Webtechnick CakePHP-Facebook-Plugin permissions not working

I'm using the Webtechnick CakePHP-Facebook-Plugin in order to log my users into my CakePHP application, I need to get their user_relationship, user_relationship_details, user_religion_politics and email.
Im using something kike this to invoke the login button
echo $this->Facebook->login(array('perms' => 'email,user_religion_politics,user_relationships,user_relationship_details', 'redirect' => array('controller' => 'users', 'action' => 'facebook'), 'label' => __('<span class="icon-facebook-sign"></span> Login with facebook',true),'id' => 'facebook_btn' ));
And also in facebook on "App details" in the "Configure App Center Permissions" section I'm adding the permissions too, but its not working, when a user login into the app facebook is still requesting the default perms (public profile, friends list and email).
I solved it, It seems that I was missing $options parameter on my init function.
So I changed the call in my default.ctp file
from
$this->Facebook->init();
to
$this->Facebook->init(array('perms' => 'email,user_religion_politics,user_relationships,user_relationship_details'));
I solved it, It seems that I was missing $options parameter on my init function.
So I changed the call in my default.ctp file
from
$this->Facebook->init();
to
$this->Facebook->init(array('perms' => 'email,user_religion_politics,user_relationships,user_relationship_details'));

Page Admin - Graph Api Comment as User

its a bit complicated because i dont understand might be a bug.
OR MAYBE i making a mistake.
User allows the Application and the same time user ist the Admin of the Fanpage.
I store all Data Accesstoken uid etc.. in the Database.
Now i want to post comments on a Photo as the user (The user is also Admin of the Fanpage)
The problem is that the comment is posted Successfully but the Comment is from Fanpage.
I just want to post as the user as he is.
Im using the Access Token of the User which i stored in the Database and also using Form fields with name & id.
Anybody out there facing the same problems ?
$details = array( 'message'=> $photodata,'access_token' => $tok, 'from' => $from);
$from = array( 'name'=> $nome,'id' => $ad);
$addscomment = $facebook->api("".$photoid."/comments", 'post', $details);

how to post facebook user wall/ page status by a single user only no app install for other users

I am working on a site and i need to post page links from that site to a special user wall or page if something is published on it which means i only need one user to post that question.
the problem which i am facing is access token since i am not trying to show facebook login page in front of website traffic. its not like sharing on user wall we are basically trying to post status on a page automatically so any help for this problem will be appreciated.
i am using the following code which seems to work fine as long as the access token for the page is valid but i need to make something permanent so that i can add all the info in the php code hardcoded and it work for some weeks at-least without changing the api key or token
$appid = 'code';
$appsecret = 'code';
$wall= $pageId = 'code';
$token='page token';
$facebook = new Facebook(array('appId' => $appid, 'secret' => $appsecret, 'cookie' => true));
$params=array( 'message' => $msg,'name' => $title, 'caption' => $title, 'link' =>$uri,'description' => $desc, 'picture' => $pic, 'access_token' => $token,'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) );
$result = $facebook->api($wall.'/feed/','post',$params);
if i make token from the graph api debug page then it works fine but after some time i got the message "OAuthException: An active access token must be used to query information about the current user."
i am really desperate to find something solid for it.
thank you
You can write a backend script (maybe a cron job using the FB PHP-SDK) that runs as the special user and makes the desired FB api calls. For this, you will want to use a long-lived access token, which needs to be renewed every 60 days. You might also try your FB api calls using an App Access Token, which do not expire but also do not support all FB publishing and other operations.
To post to someones wall (or perform any action with the open graph) you must be authenticated with facebook as somebody in their graph or an application that they have granted permission to.
You should look at the permissions that can be set using the oauth scope attribute...
https://developers.facebook.com/docs/reference/dialogs/oauth/
To me it looks like they will need to grant your application publish_stream if you want to write to their friends walls as well as the user that you are authenticated as.
https://developers.facebook.com/docs/reference/login/extended-permissions/

Prevent signups with Facebook proxy email

Problem is, when a user clicks on FB Login button on my site, Facebook API throws him with a window which ask for access permissions(which is the usual flow). But when the user chooses the proxy mail address (anonymous), then I want to force the user to login only using his real email id.
How am I supposed to handle this ?
I can detect that user used proxy email and prevent him from registering, but then I can't remove my app from his list of authorized apps - meaning I can't get him to that initial dialog for choosing which email he will provide.
You can't force the user to go through the authorization dialog again, because as far as Facebook is concerned, the user has installed your application and nothing else needs to happen. The best thing you can do here is write your own form which informs the user that the Facebook proxy e-mail address is unacceptable and you need a real e-mail address. Unfortunately, this does not force the user to give you their Facebook account e-mail address, or even a real e-mail address. This is the best we have via Facebook though, and it's just something we have to deal with.
UPDATE 5/10/11
I was browsing around the Facebook documentation, and found a method that exists in the old Legacy REST API which actually allows you to remove extended permissions for your app from a user. I think you could use this exact API call to manage getting non-proxy addresses from your Facebook user, while still using the native install dialog.
I tested this using the FB JS SDK and it worked! The method you need to use is the auth.revokeExtendedPermission method. Here are 2 examples of calling that method via the JS SDK and the PHP SDK.
Javascript:
<script>
FB.api({
method: 'auth.revokeExtendedPermission',
perm: 'read_stream'
}, function(response)
{
console.log(response)
});
</script>
PHP:
<?php
$facebook->api(array(
'method' => 'auth.revokeExtendedPermission',
'perm' => 'email',
'uid' => $uid
));
Because these use the Legacy REST API they're not as "supported" as the new Graph API. I've not seen anything regarding migrating this feature to the Graph API. Hopefully they will.
Invoke revocation of the app through graph api (as below) with the php sdk then redirect user back through your dialog with this non-proxy requirement explained.
private function revokeAccess() {
$access_token = $this->facebook->getAccessToken();
$result = $this->facebook->api(array(
'method' => 'auth.revokeAuthorization',
'uid' => $this->{facebook id here},
'access_token' => $access_token
));
return $result;
}
This code is php.
This completely removes the app.
Returns 1 on success; 0 on failure.
$this->facebook == facebook object from the facebook php sdk.