How to confirm email addrees in spring MVC web application - java

I am registering user with email address . but i want to send the user a confirmation link where if they click then their email address gets confirmed
I am using java spring MVC hibernate mysql

Among other tools you can use "java mail" package to send emails direclty from your application. Here's the link to API docs Java Mail API
So the scenario could be like the following:
User account is created. It's in unconfirmed state now;
You generate a unique confirmation ID to your applicaiton. The easiest way is to use java.util.UUID.randomUUID().toString(). UUID is a random globally unique value.;
You store the ID (e.g. 0123)+account to the database for future use;
Send the URL+ID (http://yourapp.com/confirm?id=0123) as an email using javamail to the user;
Do not show the ID in browser now;
The user checks inbox and see your letter;
The user clicks the link and request is sent to your site confirmaion servlet;
Confirmation servlet will search for the account associated with the specified confirmation id;
Confirmaion servlet set account to "confirmed state" as obvously the user has access to the specified mail box

Use Java Mail Api to create a e-mail with confirmation. Also, you need to generate unique id to confirm the user - this info can be stored in db. After the moment user clicks on your confirmation link you should set user in 'Confirmed' state.

Related

Telegram bot How to get link to user profile from a message they send

I'm working with telegram bot and i have this method to get user messages.
I need to find a way to get a link to the user who send this message
I saw there are this method, but i dont know how to connect them to a "link" to a profile
#Override
public void onUpdateReceived(Update update) {
update.getMessage().getFrom();
// i have: getFirstName(), getLastName() - not helping
// i have also getId() - but its a number how do i convert it to a link to telegram profile ?
}
Having username is optional on Telegram, setting it up means other people will be able to contact the user without knowing their phone number. Only users that chose their username in Telegram settings have a profile link, and the link is of the form https://t.me/<username>.
For ordinary messages, you can get the username via update.getMessage().getFrom().getUsername() and use it to create profile links, however, note that for many users this value will be empty (meaning they don't have a profile link).
Also, if you keep database of chat IDs, you can get usernames of the users via getChat Telegram API call. This can be useful because while usernames can be changed by the user any time (meaning their profile link will also change), chat ID of the user is constant over time and the getChat method will always provide you with the most recent information.

firebase auhentication both email and phone sms verification

In Firebase, I register the user with e-mail on the authentication side and after registration I send e-mail verification to this user, but in addition to this, I define some other features in my system, such as name, phone number while registering. I will combine these features and keep them in user collections in firestore. At the same time, I want to send an sms-code to the phone number of the data whose e-mail and password are matched in the user collections with the e-mail and password entered by the user while logging in to the system, and I will instantly verify this every time for the user to log in. Is it possible for me to do something like this or should I just choose one over email or phone?
Yes absolutely it is possible, use both authentication method one by one (email first then phone OTP) and while registering after creating user with email and password and sending otp to the user, instead of doing createUserWithCredentials use linkUserWithCredentials. This will create one user with both email and phone number authentication instead of creating two separate users for two different credentials.

How to test an integration to mercadopago using test users?

In order to test a MercadoPago integration the documentation tells that you need at least two test users: a seller and a buyer. It also explains how to create them but not how to use them.
I suppose the seller info should be hard-coded somewhere in the server side. Where? Is there a field in the preference data to specify the seller user?
I know there is a payer field and I used it to specify the buyer. But what about the seller?
I already tried filling the client_id and collector_id fields of the preference data with the test-user id with no avail.
MP mp = new MP("???", "????");
JSONObject preference = mp.createPreference("{items:[...], client_id: 262046207}");
Where 262046207 is the test-user id of one of the two test users I generated.
When the user submits a payment he gets this error message: "Una de las partes es un usuario de prueba."
Steps:
Create two test users: one for acting as the buyer, and the other for acting as the seller. Here are the instructions to create a test user.
Log out if you are already logged in.
Log in to MercadoPago with the seller test user using the e-mail and password you obtained in step 1. If the login dialog asks for your password before the e-mail, click the link "no soy ..." which is below the login dialog.
Then go to this link to obtain the credential you need to authenticate programmatically from the server.
Then go to this link to configure the URL where your server will listen to the MercadoPago notifications. If you have a router, don't forget to open the port.
At the time of testing a purchase, log in to MercadoPago with the e-mail and password of the buyer test user.
To pay with credit cards, use any of these cards numbers. The other fields can be filled with anything, but the card holder's name should start with any of the prefixes enumerated at the bottom of the mentioned page.

how to implement the create new password functionality directly from user's email

I am trying to implement the scenario in which a new user has been created in my application by Admin.
1st step will be
user has allotted by a temporary password
and receives the email with an activation link
User will just by clicking on that link taken to the create new password page , he creates his new password and thats it.
Now my query is how will the application knows that which user is this ,just by clicking that activation link in his email
Activation links carry a long token, such as activate.jsp?tok=98357627272357852786276258763427934579342579342793426734279. This token can be randomly selected, and stored in a database. When the page is loaded, the token is looked up, and the correct user gets authenticated. The token may then be deleted from the database.

How to verifiy a email during signup?

I'm developing a website with using struts2 and hibernate as back end. In many sites after you sign-up, a link will be sent to your email and after clicking on that the registration is complete. I want this feature on my webstie, but I don't have any idea how to do this and how is this working? i needsome example to do this....
I have never messed around with struts, but basically what you could do would be to send an email with a link which directs to a specific page. When a user signs up to your website you could save, amongst other things, the email address of the user, the time stamp of the registration and also a key (could be the hash of the email and password, for instance).
You then construct the link and include the email and key in the query string. Once that the user clicks the link, in your page you make a check to see that the user is still within some time frame (optional) and that the email given matches the given key (which you have stored in the database).
If the email and key match, then activate the account.
This is broad question but I am answering based on verification
1. You need a signup page with form example /signup.jsp
2. After basic fields and email validation, generate a code xyzcode for this email,
3. Send email to user email, using a mail server with a link to your link validation page like
/validate.jsp?code=xyzcode (mail server setup and sending email is beyond the scope of the answer)
4. On validate.jsp check code and validate any email with this code otherwise give respective error message.
There are multiple approaches but I am suggesting one which will be easy and as per standard..
In user table add extra column as Status [which can take two values either inactive or Active]
create one more table(emailauthentication) where columns will be (key,emaiId)..
Now what u have to do is after user click submit with registration data...gnerate a dynamic key..could be timestamp+emailId(or anything dynamic and unique) and create record in user table with status as inactive and create record in emailauthentication table with this generated key and emaiId..now after record is created generate a URL which could be like
<a href="doAuthenticationForUser?authenticationId='dynamicKey'"/>Click to authenticate</a>
Now when user clicks this URL then in the action class or Service for this authenticationId find the emailId and make the column status as active..
It is true it is quite big to answer the question.
I knew one link which has the best answer given by BalusC
Here is link:better answer.
I have implemented in my project. I hope this link will help others.
Thanks for reading.

Categories