Skip to content

Commit

Permalink
[mirotalkwebrtc] - add demo user
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed May 12, 2024
1 parent a90977b commit c824390
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
9 changes: 8 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ EMAIL_PORT=emailPort
EMAIL_USERNAME=emailUsername
EMAIL_PASSWORD=emailPassword

# User allowed without requiring registration for demonstration purposes of the platform

USER_DEMO_MODE=false # true or false
USER_DEMO_USERNAME=demo
USER_DEMO_PASSWORD=Demo@123
[email protected]

# User Registration (If false, only the existing user, created by the admin via API, can access to the platform)

USER_REGISTRATION_MODE=true # true or false

# Admin credentials
# User identified as Admin by this credentials

ADMIN_EMAIL=admin@email
ADMIN_USERNAME=adminUsername
Expand Down
16 changes: 15 additions & 1 deletion backend/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const log = new logs('Controllers-users');

const USER_REGISTRATION_MODE = process.env.USER_REGISTRATION_MODE == 'true';

const USER_DEMO = {
enabled: process.env.USER_DEMO_MODE == 'true',
username: process.env.USER_DEMO_USERNAME,
password: process.env.USER_DEMO_PASSWORD,
email: process.env.USER_DEMO_EMAIL,
};

async function userCreate(req, res) {
try {
const { email, username, password } = req.body;
Expand Down Expand Up @@ -60,6 +67,12 @@ async function userLogin(req, res) {
const { email, username, password } = req.body;
const dateNow = new Date().toISOString();

const isUserDemo =
USER_DEMO.enabled &&
email === USER_DEMO.email &&
username === USER_DEMO.username &&
password === USER_DEMO.password;

const payload = { username: username, email: email, password: password };
const token = utils.tokenEncode(payload);

Expand Down Expand Up @@ -98,7 +111,8 @@ async function userLogin(req, res) {
log.error('USER REGISTRATION MODE DISABLED, user not found!');
return res.status(201).json({ message: 'User not found!' });
}
if (nodemailer.EMAIL_VERIFICATION) {
log.debug(`User demo: ${isUserDemo}`);
if (!isUserDemo && nodemailer.EMAIL_VERIFICATION) {
log.debug('New user, send email confirmation');
const confirmationCode = `?token=${token}`;
nodemailer.sendConfirmationEmail(username, email, confirmationCode);
Expand Down
2 changes: 1 addition & 1 deletion frontend/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @license For private project or commercial purposes contact us at: [email protected] or purchase it directly via Code Canyon:
* @license https://codecanyon.net/item/a-selfhosted-mirotalks-webrtc-rooms-scheduler-server/42643313
* @author Miroslav Pejic - [email protected]
* @version 1.0.78
* @version 1.0.79
*/

const isMobile = !!/Android|webOS|iPhone|iPad|iPod|BB10|BlackBerry|IEMobile|Opera Mini|Mobile|mobile/i.test(
Expand Down
4 changes: 1 addition & 3 deletions frontend/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ function signupOrLogin(data) {
.then((res) => {
console.log('[API] - USER LOGIN RESPONSE', res);
if (res.message) {
res.success
? popupMessage('success', res.message)
: popupMessage('warning', res.message);
res.success ? popupMessage('success', res.message) : popupMessage('warning', res.message);
res.message.includes('Pending') ? showLogin() : showSignUp();
} else {
window.sessionStorage.userId = res._id;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalkwebrtc",
"version": "1.0.78",
"version": "1.0.79",
"description": "MiroTalk WebRTC admin",
"main": "server.js",
"scripts": {
Expand Down

0 comments on commit c824390

Please sign in to comment.