I have a contact Form in my App. I am adding email field dynamically when user clicks on add Email button. if user may or may not enter the value after email field generated when he clicks on add Email button.
If user not enter the value of Email and he clicks on submit, the angularjs sending data as emails[{"key":"Work","value":"user#domine.com"},{"key":"","value":""}] to server.
How to remove these type of empty objects (like {"key":"","value":""}) while submitting the form to server.
Just before send check if if email.value is "" and remove it from array there jsbin :
$scope.send = function() {
angular.forEach($scope.emails, function(email, index){
if(email.value ===""){
$scope.emails.splice(index, 1);
}
});
Related
I would like to implement this authentication flow in Keycloak:
A user creates an account by typing only his email
The user is logged in and can access my service
2'. At the same time, an email is sent to him, allowing him to "finalize" his account
The user leaves his session -> to reuse my service, he must click in the received email
By clicking in the received email, the user defines his first password
The user is then logged in automatically (without going through a login page).
The objective of this flow is to be the simplest, to hook users who are not used to webapps.
The implementation I would do:
Create an account without password request: I customize the Keycloak Registration flow by disabling the Password Validation and Profile Validation rules
Programmatically, in my webapp, at the first connection of a user, via the REST Admin API, I trigger the email action UPDATE_PASSWORD
I get something that works, but:
A. The link received by email redirects to an intermediary page confirming the execution of actions ("Perform the following action (s)") - (similar to Keycloak Implement Reset password flow same as forgot password flow)
B. The user is then redirected to a login page, and not directly connected to the application.
When, as a normal user, I trigger a reset password request (through 'forget password' feature), the process is the one I want: by clicking on the email link, I go directly to the page allowing me to enter and confirm a new password, then I'm authenticated.
My question: Do you see a way to implement this 'simplified' flow?
My keycloak version : 11.0.2
Thank you !
I could remove the "info.ftl" page display, customizing the "ExecuteActionsActionTokenHandler", as explained here :
action-token-spi
You have to create a file :
src/main/resources/META-INF/services/org.keycloak.authentication.actiontoken.ActionTokenHandlerFactory
containing the name of the class you want to use instead :
com.example.ExecuteActionTokenHandlerFactory
Then you create that class com.example.ExecuteActionTokenHandlerFactory with the following code :
public class ExecuteActionTokenHandlerFactory extends ExecuteActionsActionTokenHandler {
#Override
public Response handleToken(ExecuteActionsActionToken token, ActionTokenContext<ExecuteActionsActionToken> tokenContext) {
AuthenticationSessionModel authSession = tokenContext.getAuthenticationSession();
String redirectUri = RedirectUtils.verifyRedirectUri(tokenContext.getUriInfo(), token.getRedirectUri(),
tokenContext.getRealm(), authSession.getClient());
if (redirectUri != null) {
authSession.setAuthNote(AuthenticationManager.SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS, "true");
authSession.setRedirectUri(redirectUri);
authSession.setClientNote(OIDCLoginProtocol.REDIRECT_URI_PARAM, redirectUri);
}
token.getRequiredActions().stream().forEach(authSession::addRequiredAction);
UserModel user = tokenContext.getAuthenticationSession().getAuthenticatedUser();
// verify user email as we know it is valid as this entry point would never have gotten here.
user.setEmailVerified(true);
String nextAction = AuthenticationManager.nextRequiredAction(tokenContext.getSession(), authSession, tokenContext.getClientConnection(), tokenContext.getRequest(), tokenContext.getUriInfo(), tokenContext.getEvent());
return AuthenticationManager.redirectToRequiredActions(tokenContext.getSession(), tokenContext.getRealm(), authSession, tokenContext.getUriInfo(), nextAction);
}
}
Actually it is the same implementation as the upper class, except we removed the following part :
if (tokenContext.isAuthenticationSessionFresh()) {
...
}
which means that if the user did not have a session, which happens when the user is reseting his password, he is redirected to that "info.ftl" page.
As a workaround for problem A, I customize info.ftl template page. I add an ugly inline script to click on the link, redirecting automatically to the update password page.
<#import "template.ftl" as layout>
(...)
<#elseif actionUri?has_content>
<p><a id="yolo" href="${actionUri}">${kcSanitize(msg("proceedWithAction"))?no_esc}</a></p>
<script>document.getElementById('yolo').click()</script>
(...)
It'll do the job until I found a cleaner solution.
At the moment, B problem remains.
Flutter webview need to autofill the values form app session in the username and email fields. I am not able achieve it using flutter webivew. I tried with flutter InAppWebView but unable to achieve it is there any to make it work with flutter webview.
It means you are not really storing the values to your session. Use user sessions instead. Check out Consession. The package adds user session support in Flutter and is easy to use.
// Store value to session
await Consession().set("user", jsonencode(user));
// Retrieve item from session
dynamic user = await Consession().get("user");
controller.evaluateJavascript(
//'''var email = document.getElementById("user");''';
source: '''
var email = document.getElementById(" Your Email document id from html");
var password = document.getElementById("Your Email document id from html");
email.value = "$email";
password.value = "$pass";
document.getElementById('password id from html page').click();
''');
Use above code to autofill using javascript by getting ids of html webpage using page inspection,The code should be used after webpage finishes loading
Laravel5 Currently i am facing issue unable to check the status email is sent and not even getting email failed and i am using mandrill api for sending emails
$mail = Mail::send('emails.pendingorder', $data , function($message) use ($domain, $order)
{
if ($order->other_email) {
$message->from($domain->email, $domain->website);
$message->to($order->email, $order->name)->subject('test Email ');
$message->bcc($order->other_email, $order->name)->subject('test Email ');
}else{
$message->from($domain->email, $domain->website);
$message->to($order->email, $order->name)->subject('test Email ');
}
});
if($mail){
echo 'sent';
}else{
echo 'Fail';
}
The second thing..
i created email templates in blade and i want to preview email in ckeditor if there any any chaning or modification require then i edit the content and send email. i havn't any idea how to to this :(
Its my first try with laravel email and i am totally stuck with it
Do you have correct configuration in config/mail.php? Remember to change pretend to false. Also, Mail::send returns void, so you will have to check status on your mandrill account.
For editing email before sending it:
create form with ckeditor
fill this form with your default template
after submitting you have email body in your request, you can pass it to your email view
If you want your email to be fully editable, instead of having email view with only one variable you can use:
Mail::raw('This will be body of your email', function($message) {
// ...
});
In my meteor app, I'm setting up the registration process.
Meteor has a Account.sendVerificationEmail method to send emails out to new users with a token to verify their email address
My app does need this functionality but I don't really want to use the sendVerificationEmail to send the emails because I already have my own email helper which has got a bunch of logic and I want all the emails in my system to pass to flow out of that function.
So my question is that I do want to create my verification token for the user on registration, but I don't want sendVerificationEmail to send an email out because I want to do it manually.
Is this possible?
First add the core "random" package for random code generation
$ meteor add random
Then intercept the account creation process
Accounts.onCreateUser(function(options, user) {
// create a verified flag and set it false
user.customVerified = false;
//20 character random lowercase hex string. You can use a hash of some user info if you like. I just put this here for demonstration of the concept :)
user.customVerificationCode = Random.hexString(20).toLowerCase();
//pass the new user's email and the verification code to your custom email function so that you can craft and send the mail. Please double check the option.profile.emails[0], the email should be available somewhere within the options object
myCustomEmailFunction(options.profile.emails[0], user.customVerificationCode);
// continue with account creation
return user;
});
At this point, if you don't want to show pieces of ui elements to unverified users, you can create a template helper for that. Or you can check if user is verified in your publications. Etc... whatever you want to restrict.
Now you can define a route in your app with iron router so that when the user clicks on the link, the route takes the verification code and set's the user's verified flag to true.
You can fake the verification record for the user in the MongoDB document and then send your own email:
//Fake the verificationToken by creating our own token
var token = Random.secret();
var tokenRecord = {
token: token,
address: Meteor.user().emails[0].address,
when: new Date(),
};
//Save the user
Meteor.users.update(
{_id: Meteor.userId()},
{$push: {'services.email.verificationTokens': tokenRecord}}
, function(err){
//Send an email containing this URL
var confirmUrl = Meteor.absoluteUrl() + '#/verify-email/' + token;
//Send using SendGrid, Mandrill, MailGun etc
});
Code taken from GitHub:
https://github.com/meteor/meteor/blob/5931bcdae362e1026ceb8a08e5a4b053ce5340b7/packages/accounts-password/password_server.js
As per the documentation in the following link, we can get the user id if the uer will interact with the form..
http://wiki.developers.facebook.com/ind … d_Policies
"If a viewing user interacts with the tab (like submits a form, takes an action that causes an AJAX load of new content, or follows a relative URL that loads on the tab), that user's UID is sent to the application as the fb_sig_user parameter, the profile owner's user ID is sent as the fb_sig_profile_user parameter. The viewing user's session key is key is sent only if the user authorized the application. "
In my fan page tab am I have an AJAX form which the user can submit with some value.. now I need the users id also.. how can I get this..
I tried to get the value in my AJAX submit page using $_POST['fb_sig_user'] with no success.. can anyone help me with this please..
You won't be able to get the id of the user using $_POST['fb_sig_user'] unless you authenticate the user by having this in the facebook's ajax function:
ajax.requireLogin = true;
For example, I'm retrieving it fine with this:
function do_ajax(url, div_id)
{
document.getElementById('poller_waitMessage').setStyle('display', 'block');
var ajax = new Ajax();
ajax.responseType = Ajax.FBML;
ajax.onerror = function(error)
{
new Dialog().showMessage("Error:", "Some communication error occured, Please reload the page.","Ok");
};
ajax.ondone = function(data)
{
document.getElementById('poller_waitMessage').setStyle('display', 'none');
document.getElementById(div_id).setInnerFBML(data);
}
ajax.requireLogin = true; // <----- this is important
ajax.post(url);
}
I've been happily using the form variable fb_sig_profile_user for previous apps, and when developing a new app last week, the variable was no where to be found.
Searched for several days, I was about to give up, and then the found answer:
ajax.requireLogin = true;
I understand FB cares about privacy and all, but they really need to announce these kinds of changes before just taking it away.
Million Thanks!