#ecommerce

1404 messages · Page 2 of 2 (latest)

late mason
#

not some fake email

#

link will be send to email click on it and your in

warped agate
#

On Registration an email can be send for verification. But not necessarily.

late mason
#

thats the acc active and inactive part

late mason
#

and then he compained he didnt get the order confirmation

#

i did some pros and cons

warped agate
late mason
#

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

warped agate
#

correct.

#

Have you found out smth you didn't know?

#

Are there any more quesions?

late mason
late mason
late mason
#

and also share body for addproduct in postman

#

im getting product sttring missing error

warped agate
#

new repository

#

You can check the differences with your code. And if there are not many differences you can fork from it and pull.

late mason
#

damn some pom dependency is missing

#

no imports showing

#

is it the java=EMAIL DEPENDECY

warped agate
#

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

late mason
warped agate
#

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

late mason
#

your imports showing error

warped agate
#

for me works

late mason
#

should i download new dependecy

#

then try import

warped agate
#

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

late mason
#

i added new dependency half imports were working

#

mime werent working to i cahnged javax to jakarta

#

2 still left

warped agate
#

yea go on

#

you can try to press keyboard combination: ctrl+shift+O and eclipse should add and fix imports automatically. If it can

warped agate
#

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

late mason
#

add sun mail and springcontext dependency error gone

warped agate
#

sometimes when you press ctrl+s - saving the class file then Java compiles it and errors suddenly vanish.

late mason
#

i do that everytime ctrl shift s

#

lets just test the email

warped agate
#

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

late mason
#

was just seeing it

#

nothing is there

warped agate
#

you have to add you database login username and password

#

and also your own SMTP server login and app password

warped agate
late mason
#

properties

warped agate
#

show it. I want to see it

late mason
warped agate
#

all application.properties info between 2 triple quatation marks. Or print screen it

#

then I will show you mine

late mason
#

ill just screenshot it

warped agate
#

ok

late mason
#

just tell me what in what line by no

warped agate
#

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

late mason
warped agate
#

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>

late mason
warped agate
#

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

late mason
#

so i make a new notepad with extention .env

#

and save it were

warped agate
#

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

late mason
#

whats in gitignore

#

i saw it okay

warped agate
#

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

late mason
#

never tried using email data before

#

and you cant access my database

warped agate
#

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

warped agate
#

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

late mason
#

i have 2 step verification on

#

is your gitignore

#

default file

#

if yes share it please

warped agate
late mason
warped agate
#

yes

late mason
#

database name as in schema name

#

or sql username and pasword

warped agate
#

leave as is

#

fambruh

#

schema

late mason
#

im talking about in in env file

warped agate
#

no don't add there database name

#

only your sql user username

#

and password

#

perhaps you call it sql username and password

late mason
#

and email and password

warped agate
#

email your own gmail email address

late mason
warped agate
#

app password - is 16-digit application password specifically generated by Google for your account login through the app

warped agate
#

you should have your own

late mason
#

ahh

#

so database name password

#

email and password

warped agate
#

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

late mason
#

damn

#

yup we r on same track

#

for a second i thought im getting confused

warped agate
#

Yea I also read it. try pressing links and search

late mason
warped agate
#

I do't remember what I pressed there.

late mason
#

advanced setting?

warped agate
#

I try t to find it again

late mason
#

endless links

warped agate
#

but IU found it after some searches

warped agate
#

as soon as I will find I wil lgive you

warped agate
#

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: ....

late mason
#

main_username whatever name i used

warped agate
#

Have you generated it?

late mason
#

yup

warped agate
#

ok cool

late mason
#

there are 4 inputs in the env you shared

#

database and password

#

email and app password

#

?

warped agate
#

yes 4 inputs

late mason
#

ok i got it

warped agate
late mason
#

i cant even share to see im doing correct or not

warped agate
#

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

late mason
warped agate
#

You will learn

#

If you want

late mason
#

we set

warped agate
#

Before you launch your Spring boot application go to terminal and get to the root of your project:

#

go here

#

do: source .env

late mason
#

from git bash or cmd

warped agate
#

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

late mason
#

multiple files with same name in downloads

#

had to remove it from downloads

#

then renamed it

warped agate
#

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

late mason
#

no src folder showing now

warped agate
#

The constructor: public void sendMessageWithAttachment(String to, String subject, String text, String pathToAttachment)
tells yu what each parameter means

warped agate
#

what have you done?

#

deleted?

late mason
#

its there

#

but not showing during upload

warped agate
#

expand it

late mason
#

gitignore lmao

#

nope not showing

warped agate
#

I don't understand what are you trying to do. And to show

late mason
#

everything in there

#

but not showing after uploadng installing in sclpse

warped agate
#

For me it is showing

#

I don't know what happens on your PC

#

I'm on desktop PC, Windows10

late mason
#

its working

#

my bad was checking archives

warped agate
#

solve the attachment problem before you launch Spring Boot app

late mason
warped agate
#

go to JwtController

late mason
warped agate
#

good, now:
Change this line

#

PATH to your own computer file

#

for example image

late mason
#

the path pattern is diffferent hmm

warped agate
#

it should be

late mason
#

ok next

warped agate
#

show it

late mason
warped agate
#

ok now go to the /g/Java_programavimas/macc-project/ecommerce in terminal

#

tell me when done

late mason
warped agate
#

~/downloads/springboot/ecommerce-main

#

ok now show the list with ls -a

#

there should be .env file

late mason
#

only Fambru

#

i put .env file inside fambru

warped agate
#

ok then navigate to ~/downloads/springboot/ecommerce-main/Fambru

#

enter command source .env

late mason
warped agate
#

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

late mason
#

bash: .env: No such file or directory

warped agate
#

no good

#

perhaps this file is in upper directory

#

go to cd ..

#

and do there ls -a

#

and make sure there is .env file

late mason
#

./ ../ Fambru/

warped agate
#

:/

#

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:

late mason
#

i just created new file

#

with right click

warped agate
#

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

late mason
#

in which folder should i create it inside fambru

warped agate
#

No, 1 level higher: ~/downloads/springboot/ecommerce-main

#

this is the root

late mason
#

but when uploading the springboot project in eclipse i use the Fambru folder directly

warped agate
#

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

late mason
#

still nothing

warped agate
#

Fambru is backend folder which is used by the Eclipse

#

What are you doing?

late mason
#

source .env

warped agate
#

if console doesn't write anything then it means it is OK

#

IS it like this?

late mason
#

bash: .env: No such file or directory

warped agate
#

Have you created such file?

late mason
#

.env yeh do i need to ad filename

warped agate
#

no, not necessarily

#

Is the file inside the folder?

#

show it

late mason
#

emailusername created wih nano

warped agate
#

what is the file named email.env? show the contents

late mason
#

its the one i created with right click

warped agate
#

Do you have nano editor in terminal?

#

be faster

#

a command

#

that launches terminal text editor

late mason
#

nope i just started nano named the file and save it

#

in git bash only

warped agate
#

show what is the file named

#

do ls -a

late mason
warped agate
#

you don't need that meny env files. it is enough to have 1 .env. No matter.

#

then do source email.env

late mason
#

damn finaly nothing happened

#

i was thinking of trying this from the beginning

#

what next

#

lets speed up

warped agate
#

launch the app on the terminal using command: ./mvnw spring-boot:run

#

if everything is ok then it should launch without errors

#

without exceptions

late mason
#

$ ./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

warped agate
#

yes

#

but there you might need to enter environment variables manually again

#

ok launch there

late mason
#

java.sql.SQLException: Access denied for user '${DATABASE_USERNAME}'@'localhost' (using password: YES)

warped agate
#

haha, this is exactly the same problems that I had

#

ok I will tell you what to do:

#
  1. Right click on your project in the Project Explorer
    Choose Run as.. > Run configurations:
late mason
#

next

#

bro should i share screen

#

itll take forever like this

warped agate
late mason
#

i can open the chat in my mobile

warped agate
#

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

late mason
#

OK

warped agate
#

Then Apply

#

and Run

late mason
#

nothing is there even after add

warped agate
#

what do you see

#

I was afk a bit

#

I came back

#

did I missed smth

#

Or do you want to share the screen

late mason
#

i added everything with variable and values

late mason
#

no need voive

warped agate
#

What program should I use

late mason
#

ill share here

#

ok it works only in dm

warped agate
#

Here on discord I have never shared screen

#

I don't know how to do it

#

but if you do then do

#

lets go in dm then