Skip to content

Commit

Permalink
add email validation with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Subas-mohanty committed Oct 22, 2024
1 parent 7734aa6 commit d8a6637
Show file tree
Hide file tree
Showing 7 changed files with 5,420 additions and 4,328 deletions.
2 changes: 1 addition & 1 deletion apps/api/server/routes/api/articles/[slug]/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HttpException from "~/models/http-exception.model";
import articleMapper from "~/utils/article.mapper";
import articleMapper from "~/routes/api/utils/article.mapper";
import {definePrivateEventHandler} from "~/auth-event-handler";

export default definePrivateEventHandler(async (event, {auth}) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/server/routes/api/articles/[slug]/index.put.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HttpException from "~/models/http-exception.model";
import articleMapper from "~/utils/article.mapper";
import articleMapper from "~/routes/api/utils/article.mapper";
import slugify from 'slugify';
import {definePrivateEventHandler} from "~/auth-event-handler";

Expand Down
2 changes: 1 addition & 1 deletion apps/api/server/routes/api/articles/feed.get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import articleMapper from "~/utils/article.mapper";
import articleMapper from "~/routes/api/utils/article.mapper";
import {definePrivateEventHandler} from "~/auth-event-handler";

export default definePrivateEventHandler(async (event, {auth}) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/server/routes/api/articles/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import articleMapper from "~/utils/article.mapper";
import articleMapper from "~/routes/api/utils/article.mapper";
import {definePrivateEventHandler} from "~/auth-event-handler";

export default definePrivateEventHandler(async (event, {auth}) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/server/routes/api/articles/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import articleMapper from "~/utils/article.mapper";
import articleMapper from "~/routes/api/utils/article.mapper";
import HttpException from "~/models/http-exception.model";
import slugify from 'slugify';
import {definePrivateEventHandler} from "~/auth-event-handler";
Expand Down
5 changes: 5 additions & 0 deletions apps/api/server/routes/api/users/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ export default defineEventHandler(async (event) => {
const username = user.username?.trim();
const password = user.password?.trim();
const {image, bio, demo} = user;
const regex = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$");

if (!email) {
throw new HttpException(422, {errors: {email: ["can't be blank"]}});
}

if(!regex.test(email)){
throw new HttpException(422, {errors : {email : ["must be a valid email address"]}});
}

if (!username) {
throw new HttpException(422, {errors: {username: ["can't be blank"]}});
}
Expand Down
Loading

0 comments on commit d8a6637

Please sign in to comment.