Skip to content

Commit 1c2bfc0

Browse files
Merge pull request #469 from bounswe/dev
Dev to Master
2 parents 46de6a6 + af90a4b commit 1c2bfc0

File tree

203 files changed

+39808
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+39808
-192
lines changed

deliverables/CMPE451_Customer_Presentation_Milestone_1/deliverables.md

+584
Large diffs are not rendered by default.

learnify/backend/.dockerignore

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env.development.local
77+
.env.test.local
78+
.env.production.local
79+
.env.local
80+
81+
# parcel-bundler cache (https://parceljs.org/)
82+
.cache
83+
.parcel-cache
84+
85+
# Next.js build output
86+
.next
87+
out
88+
89+
# Nuxt.js build / generate output
90+
.nuxt
91+
dist
92+
93+
# Gatsby files
94+
.cache/
95+
# Comment in the public line in if your project uses Gatsby and not Next.js
96+
# https://nextjs.org/blog/next-9-1#public-directory-support
97+
# public
98+
99+
# vuepress build output
100+
.vuepress/dist
101+
102+
# vuepress v2.x temp and cache directory
103+
.temp
104+
.cache
105+
106+
# Docusaurus cache and generated files
107+
.docusaurus
108+
109+
# Serverless directories
110+
.serverless/
111+
112+
# FuseBox cache
113+
.fusebox/
114+
115+
# DynamoDB Local files
116+
.dynamodb/
117+
118+
# TernJS port file
119+
.tern-port
120+
121+
# Stores VSCode versions used for testing VSCode extensions
122+
.vscode-test
123+
124+
# yarn v2
125+
.yarn/cache
126+
.yarn/unplugged
127+
.yarn/build-state.yml
128+
.yarn/install-state.gz
129+
.pnp.*
130+
131+
# Ignore files related to API keys
132+
133+
# Ignore IDE specific directories
134+
.vscode
135+
.idea
136+
137+
# Ignore files/folders macOS could create in the directory
138+
.DS_Store
139+
.AppleDouble
140+
.LSOverride
141+
.DocumentRevisions-V100
142+
.fseventsd
143+
.Spotlight-V100
144+
.TemporaryItems
145+
.Trashes
146+
.VolumeIcon.icns
147+
.com.apple.timemachine.donotpresent
148+
._*
149+
150+
# Visual Studio Code related
151+
.classpath
152+
.project
153+
.settings/
154+
.vscode/*
155+
!.vscode/settings.json
156+
!.vscode/tasks.json
157+
!.vscode/launch.json
158+
!.vscode/extensions.json
159+
.history
160+
161+
# General
162+
.DS_Store
163+
.AppleDouble
164+
.LSOverride
165+
166+
# Icon must end with two \r
167+
Icon
168+
169+
# Thumbnails
170+
._*
171+
172+
# Files that might appear in the root of a volume
173+
.DocumentRevisions-V100
174+
.fseventsd
175+
.Spotlight-V100
176+
.TemporaryItems
177+
.Trashes
178+
.VolumeIcon.icns
179+
.com.apple.timemachine.donotpresent
180+
181+
# Directories potentially created on remote AFP share
182+
.AppleDB
183+
.AppleDesktop
184+
Network Trash Folder
185+
Temporary Items
186+
.apdisk
187+
188+
# Miscellaneous
189+
*.class
190+
*.lock
191+
*.log
192+
*.swp
193+
.atom/
194+
.buildlog/
195+
.svn/
196+

learnify/backend/.env.prod

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DB_URI="mongodb://mongo:27017"

learnify/backend/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ We uses Node.js and Express.js for our API.
1010
- Prepare the environment variables by generating .env file(you can find details about this bellow)
1111
- npm start
1212

13+
## Docker Installation
14+
15+
You can just run `docker-compose up` to get the DB and the API running.
16+
If you changed the code, you need to run `docker-compose up --build` to change the code in the image.
17+
1318
## Requirements
1419

1520
For development, you will need Node.js and MongoDB. In addition, you shall set your .env file.
@@ -56,6 +61,9 @@ You can list of environment variables that our API uses for configuration:
5661
#### Compulsory Variables
5762

5863
DB_URI : MongoDB URI of your local development database.
64+
JWT_KEY: key to be used for jwt generation.
65+
MAIL: mailaddress the API uses, currently only gmail is supported
66+
MAIL_PASS: password of MAIL
5967

6068
#### Optional Variables
6169

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { default as signup } from './signup.js';
2+
export { default as resend } from './resend.js';
3+
export { default as login } from './login.js';
4+
export { default as verifyEmail } from './verifyEmail.js';
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { validateLogin } from '../../validators/user_validator.js';
2+
import bcrypt from 'bcryptjs';
3+
import jwt from "jsonwebtoken";
4+
import { User } from '../../../models/index.js';
5+
6+
export default async (req,res) => {
7+
const { error } = validateLogin(req.body);
8+
if (error) {
9+
console.log(error.details[0].message);
10+
return res.status(400).json({ "resultMessage": "Please check your inputs." });
11+
}
12+
13+
const email = req.body.email;
14+
15+
let emailCheck = await User.exists({ email: email})
16+
.catch((err) => {
17+
console.log(err.message);
18+
return res.status(500).json({ "resultMessage": "Something is wrong."});
19+
});
20+
21+
if (!emailCheck)
22+
return res.status(404).json({"resultMessage": "There is no user with the given email."});
23+
24+
let user = await User.findOne({ email: email }).select('+password')
25+
.catch((err) => {
26+
console.log(err.message);
27+
return res.status(500).json({ "resultMessage": "Something is wrong." });
28+
});
29+
30+
31+
const incomingPassword = req.body.password;
32+
const databasePassword = user.password;
33+
const passwordCheck = bcrypt.compareSync(incomingPassword, databasePassword);
34+
35+
if (!passwordCheck)
36+
return res.status(409).json({"resultMessage": "Wrong password."});
37+
38+
if(!user.is_verified){
39+
return res.status(401).json({
40+
resultMessage: "User is not verified.",
41+
user: user.toJSON(),
42+
});
43+
}
44+
45+
const token = jwt.sign(
46+
{ user_id: user._id, email },
47+
process.env.JWT_KEY,
48+
{
49+
expiresIn: "24h",
50+
}
51+
);
52+
53+
return res.status(200).json({
54+
resultMessage: "Successfully logged in.",
55+
user: user.toJSON(),
56+
token: token
57+
});
58+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { User } from '../../../models/index.js';
2+
import send_verification_email from '../../../utils/auth/send_verification_email.js'
3+
4+
export default async (req, res) => {
5+
6+
const email = req.body.email;
7+
8+
let user = await User.findOne({ email: email })
9+
.catch((err) => {
10+
console.log(err.message);
11+
return res.status(500).json({ "resultMessage": "Something is wrong." });
12+
});
13+
14+
try{
15+
await send_verification_email(user);
16+
}catch(err){
17+
console.log(err.message);
18+
return res.status(500).json({ "resultMessage": "Could not send verification email." });
19+
}
20+
return res.status(200).json({
21+
resultMessage: "Verification code is succesfully resended."
22+
});
23+
};
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import bcrypt from 'bcryptjs';
2+
import { User } from '../../../models/index.js';
3+
import { validateSignup } from '../../validators/user_validator.js';
4+
import send_verification_email from '../../../utils/auth/send_verification_email.js'
5+
const { hash } = bcrypt;
6+
7+
export default async (req, res) => {
8+
const { error } = validateSignup(req.body);
9+
if (error) {
10+
console.log(error);
11+
return res.status(400).json({ "resultMessage": "Please check your inputs."});
12+
}
13+
14+
const exists_email = await User.exists({ email: req.body.email })
15+
.catch((err) => {
16+
console.log("Could not fetch users from mongoDB")
17+
console.log(err.message);
18+
return res.status(500).json({ "resultMessage": "Something is wrong." });
19+
});
20+
21+
if (exists_email) {
22+
console.log("User with existing email tried to signup")
23+
return res.status(409).json({ "resultMessage": "There already exists a user with the given email." });
24+
}
25+
const exists_username = await User.exists({ username: req.body.username })
26+
.catch((err) => {
27+
console.log("Could not fetch users from mongoDB")
28+
console.log(err.message)
29+
return res.status(500).json({ "resultMessage": "Something is wrong" });
30+
});
31+
32+
if (exists_username) {
33+
console.log("User with existing username tried to signup")
34+
return res.status(409).json({ "resultMessage": "There already exists a user with the given username." });
35+
}
36+
37+
const hashed = await hash(req.body.password, 10);
38+
39+
let user = new User({
40+
email: req.body.email,
41+
password: hashed,
42+
username: req.body.username,
43+
});
44+
45+
try{
46+
await send_verification_email(user);
47+
}catch(err){
48+
console.log("Could not send verification email.")
49+
console.log(err.message)
50+
return res.status(500).json({ "resultMessage": "Could not send verification email."});
51+
}
52+
return res.status(200).json({
53+
resultMessage: "User is successfully signed up."
54+
});
55+
};

0 commit comments

Comments
 (0)