#ecommerce
1404 messages · Page 2 of 2 (latest)
On Registration an email can be send for verification. But not necessarily.
thats the acc active and inactive part
what if some some dumb dude created a account with wrong email
and then he compained he didnt get the order confirmation

i did some pros and cons
Then it is his problem. But of course you can verify an email upon registration.
passowrd repeat is good and certain for double check email validity cant be underestimated
if we r using email verifcation on other stuff too
same email will be used for password reset
one wrong step
no emails will be sent

ill ask let me try everything and update it what you did and try it in postman
bro share your code
share your code
and also share body for addproduct in postman
im getting product sttring missing error
new repository
You can check the differences with your code. And if there are not many differences you can fork from it and pull.
damn some pom dependency is missing
no imports showing
is it the java=EMAIL DEPENDECY
you can resolve CONFLICTS
If you are using Eclipse IDE or IntelliJ you can hold mouse button on the red underlined class and it will automatically lets you choose from where to import the class
bro there is no import thats what im saying
If you have this dependency in pom xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
then it should work
add it.
refresh project onto Eclipse
or do it in maven: mvn clean install
and then it should allow you to add the SimpleMailMessage and others
your imports showing error
for me works
yes.
If you are missing the <artifactId>spring-boot-starter-mail</artifactId>
in pom xml
then add it
and wait while Eclipse downloads it automatically
i added new dependency half imports were working
mime werent working to i cahnged javax to jakarta
2 still left
yea go on
you can try to press keyboard combination: ctrl+shift+O and eclipse should add and fix imports automatically. If it can
nope
Try manually:
import java.io.File;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
You can change javax to jakarta
I see that MimeMessage and MessagingException cannot be jakarta. Leave it as javax
add sun mail and springcontext dependency error gone
sometimes when you press ctrl+s - saving the class file then Java compiles it and errors suddenly vanish.
open JwtController
class
and see how the email is sent
at login
you login and message is sent to your email
you can remove it anytime
oh you may fail;
because you have to configure it more
in application.properties
you have to add you database login username and password
and also your own SMTP server login and app password
where?
properties
show it. I want to see it
bro its very overwhelming at first tell me at what line need to put what
all application.properties info between 2 triple quatation marks. Or print screen it
then I will show you mine
ill just screenshot it
ok
yes that is what I wanted to see
In order your Spring boot application would launch you need to to have environment variables file *.env in your root folder
in that file there are key - value pairs It should contain your DATABASE_USERNAME, your DATABASE_PASSWORD, your MAIL_USERNAME and your APP_PASSWORD as keys. And = <value>
your talking about as input in properties
yea
you need such a file:
with your data
this is how we programmers hide our personal passwords from public. Otherwise it would be exposed publicly
because you share your code on github
hackers could hack your server on your web app
this file .env should be ignored
in the .ignore
At all costs protect it from sending to github
Only your Spring boot should read passwords from it
yea
save it into root folder
your root folder has directories like Fambruh/ and .git
there should be .env
and also .gitignore
in gitignore you should add:
then you can git init, git add ., git commit -m "message"
and you can push to your remote repository
and there will be no .env file
it will be only on your PC
noone will know your passwords
This is root directory/folder
of your project
files and directories that should be protected from staging, commiting and pushing to your local and remote repositories.
Thus you don't share them with other programmers
public
protect it from sending to github
You send your program code using git from console terminal
you send it to repository
it's called archiving
you can switch to any commit of you project. As it shares all stages of your commits
you can comeback to any point that your code was before
you can create branches of archiving
and share with other programmers using remote repository (Github)
they can help you and change your code. But to send to their own branches
you can pull those changes to your branch
etc
You as a programmer should know it
If you would expose your passwords and would host your web app on the Internet then hackers could hack in
and make changes and ruin your work
i get that part
If you really have your gmail 2-step Verification and also APP_PASSWORD then you will send email through gmail SMTP server
if you don't have that password then email will not be sent from your Spring Boot
there will be error
Tip: App passwords aren’t recommended and are unnecessary in most cases. To help keep your account secure, use "Sign in with Google" to connect apps to your Google Account. An app password is a 16-di
i have 2 step verification on
is your gitignore
default file
if yes share it please
this inside the env file right
yes
im talking about in in env file
no don't add there database name
only your sql user username
and password
perhaps you call it sql username and password
and email and password
email your own gmail email address
bro you have some values in there though
app password - is 16-digit application password specifically generated by Google for your account login through the app
Yes my own values
you should have your own
yea
but keep in mind that app password is not that one with which you login to your email website through browser
it is another.
app password - is 16-digit application password specifically generated by Google for your account login though the app
Go to YOUR Google account and find application password generator
somewhere in the 2-step verification tab
I couldn't find it in my Google account. I found it using help FAQ
Yea I also read it. try pressing links and search
damn just tell me what after

I do't remember what I pressed there.
advanced setting?
I try t to find it again
thats the same thing will happen to me
endless links
but IU found it after some searches
https://myaccount.google.com/apppasswords
- Visit it.
- Name your app like you want, for example "Ecommerce".
- Press button
Create. Copy password and save it to.envfile. Remove spaces. Save the file.
Also save it in your notepad where you save all your personal passwords. For example your real Google account username and password. Also add this one. But name it app password: ....
main_username whatever name i used
Have you generated it?
yup
ok cool
there are 4 inputs in the env you shared
database and password
email and app password
?
yes 4 inputs
ok i got it
You should be smart.
And find solutions
I'm teaching you, but you are 2-3 times better in Angular.
Than I in React
I have some experience in Spring as you see. But it's not big experience
you are so good in it make me feel like i didnt even learned it yet

we set
Before you launch your Spring boot application go to terminal and get to the root of your project:
go here
do: source .env
from git bash or cmd
bash better
then go to your main project folder:
start your Spring boot application using command: ./mvnw spring-boot:run
it will start it.
Then from your Angular or your browser you can login
and the email should be sent to your email address
If you have this:
//generate token
@PostMapping("/generate-token")
public ResponseEntity<?> generateToken(@RequestBody JwtRequest jwtRequest) throws Exception{
try {
authenticate(jwtRequest.getUsername(), jwtRequest.getPassword());
}catch(UsernameNotFoundException e) {
e.printStackTrace();
throw new Exception("User does not exist or invalid credentials!");
}
// validated
UserDetails userDetails = this.userDetailService.loadUserByUsername(jwtRequest.getUsername());
String token = this.jwtUtil.generateToken(userDetails);
//email.sendSimpleMessage("[email protected]", "Spring Boot test", "This message is a test message sent from Tomasm21 Spring Boot app");
email.sendMessageWithAttachment("[email protected]",
"Spring Boot email with attachment",
"This message is a test message sent from Tomasm21 ecommerce - Medicare-Backend -Spring Boot app\n"
+ "The message is with the file attachment. Download it and save as <file-name>.jpg",
"G:\\Java_programavimas\\macc-project\\images\\an-image0109.jpg"
);
return ResponseEntity.ok(new JwtResponse(token));
}
email.sendMessageWithAttachment("[email protected]", ....... <---- THIS
oh there is one more thing I forgot to tell you
the attachment
I try to send some picture/image as the attachment. And you should show the PATH to it, like: "G:\\Java_programavimas\\macc-project\\images\\an-image0109.jpg"
but this is the path to my image on my computer
you should add YOURS own.
Otherwise there will be an error.
Because this method sends an image in the attachment.
another method sends simple text email message
multiple files with same name in downloads
had to remove it from downloads
then renamed it
don't launch spring boot yet
first solve the problem with the attachment to the email message
in JwtController class
write the path of a some image or another file on your computer.
You should change this path:
to your own file path
change it
no src folder showing now
The constructor: public void sendMessageWithAttachment(String to, String subject, String text, String pathToAttachment)
tells yu what each parameter means
expand it
I don't understand what are you trying to do. And to show
For me it is showing
I don't know what happens on your PC
I'm on desktop PC, Windows10
solve the attachment problem before you launch Spring Boot app
go to JwtController
the path pattern is diffferent hmm
it should be
ok next
show it
ok now go to the /g/Java_programavimas/macc-project/ecommerce in terminal
tell me when done
~/downloads/springboot/ecommerce-main
ok now show the list with ls -a
there should be .env file
ok then navigate to ~/downloads/springboot/ecommerce-main/Fambru
enter command source .env
ls -a shows also configuration files including those that start with a dot
Have you done source .env
?
you should do it in the folder where .env file is
bash: .env: No such file or directory
no good
perhaps this file is in upper directory
go to cd ..
and do there ls -a
and make sure there is .env file
./ ../ Fambru/
:/
Where did the .env file gone?
Have you created it?
Do you remember how you created it?
if you didn't then you should do it again.
ok at the current root directory create it using nano .env
and put inside your credentials, like:
it should not be text file
it should be just a file
but no matter
extension should not be *.txt otherwise the file will not be ignored and will be exposed.
better create with nano
because it doesn't save the file with a silly txt extension
in which folder should i create it inside fambru
but when uploading the springboot project in eclipse i use the Fambru folder directly
ok then in fambru
You upload Fambru project because it is inside the root. But it doesn't mean it is root. Root is called where your .git folder is
still nothing
source .env
bash: .env: No such file or directory
Have you created such file?
.env yeh do i need to ad filename
what is the file named email.env? show the contents
same but before one
its the one i created with right click
Do you have nano editor in terminal?
be faster
a command
that launches terminal text editor
i did it here
you don't need that meny env files. it is enough to have 1 .env. No matter.
then do source email.env
damn finaly nothing happened
i was thinking of trying this from the beginning
what next
lets speed up
launch the app on the terminal using command: ./mvnw spring-boot:run
if everything is ok then it should launch without errors
without exceptions
$ ./mvnw spring-boot:run
which: no javac in (/c/Users/Junaid Shaikh/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Junaid Shaikh/bin:/c/windows/system32:/c/windows:/c/windows/System32/Wbem:/c/windows/System32/WindowsPowerShell/v1.0:/c/windows/System32/OpenSSH:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files/dotnet:/c/Program Files/Microsoft SQL Server/130/Tools/Binn:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn:/cmd:/c/Program Files/nodejs:/c/Program Files/MySQL/MySQL Shell 8.0/bin:/c/Users/Junaid Shaikh/AppData/Local/Microsoft/WindowsApps:/c/Users/Junaid Shaikh/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/Junaid Shaikh/AppData/Roaming/npm:/c/Program Files:/usr/bin/vendor_perl:/usr/bin/core_perl)
Error: JAVA_HOME is not defined correctly.
We cannot execute
u jinxed it
cant i do it from eclipse
yes
but there you might need to enter environment variables manually again
ok launch there
java.sql.SQLException: Access denied for user '${DATABASE_USERNAME}'@'localhost' (using password: YES)
haha, this is exactly the same problems that I had
ok I will tell you what to do:
- Right click on your project in the Project Explorer
Choose Run as.. > Run configurations:
i can open the chat in my mobile
Bro I have to work to show you the stuff
select Environment and then add the same variables that you added to that .env file
No, junex. We already have done a lot and we are close to the end
I think soon we will finish
OK
nothing is there even after add
what do you see
I was afk a bit
I came back
did I missed smth
Or do you want to share the screen
i added everything with variable and values
i was saying thatll be more acurate and faster
no need voive
What program should I use
