Skip to content
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codrjs/core",
"version": "1.0.0",
"version": "1.0.1",
"description": "An open-sourced customizable annotation tool",
"main": "index.js",
"repository": "[email protected]:CodrJS/Core.git",
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Email.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const EmailRegex =
/^([-!#-'*+/-9=?A-Z^-~]+(\.[-!#-'*+/-9=?A-Z^-~]+)*|"(\[\]!#-[^-~ \t]|(\\[\t -~]))+")@([0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)*|\[((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|IPv6:((((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9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A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)|(?!IPv6:)[0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+)])$/g;

export default class Email {
private $email: string;
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface IError {
status: number;
}

export default class Error<Details> extends Response<Details> {
export default class Error<Details = undefined> extends Response<Details> {
status: IError["status"];

constructor({ status, message }: IError & IResponse<Details>) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import App from "./services/app";
const Codr = { App };

export { default as App } from "./services/app";
export { default as Mail } from "./services/mail";
export { default as Authentication } from "./services/auth";
export default Codr;
87 changes: 3 additions & 84 deletions src/models/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,11 @@
import { EmailRegex } from "../classes/Email";
import { Schema, model } from "mongoose";
// import { sign } from "jsonwebtoken";

const UserProfileProvider = new Schema({
photo: { type: String },
phone: { type: String },
email: { type: String },
uid: { type: String, required: [true, "Provider's user id is required"] },
});

/* UserSchema will correspond to a collection in your MongoDB database. */
const UserProfileSchema = new Schema(
{
name: {
type: String,
required: [true, "Name is required."],
},
email: {
type: String,
lowercase: true,
required: [true, "Email cannot be blank."],
match: [
// eslint-disable-next-line no-control-regex
EmailRegex,
"is invalid.",
],
index: true,
},
providers: {
type: [UserProfileProvider],
},
},
{},
{
timestamps: true,
virtuals: {
firstName: {
get() {
const displayNameRegex =
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
const result = displayNameRegex.exec(<string>this.name);

// set name data
if (result?.groups) {
const { firstName } = result.groups;
return firstName;
}
},
},
lastName: {
get() {
const displayNameRegex =
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
const result = displayNameRegex.exec(<string>this.name);

// set name data
if (result?.groups) {
const { lastName } = result.groups;
return lastName;
}
},
},
preferredName: {
get() {
const displayNameRegex =
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
const result = displayNameRegex.exec(<string>this.name);

// set name data
if (result?.groups) {
const { preferredName } = result.groups;
return preferredName;
}
},
},
name: {
get() {
const displayNameRegex =
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
const result = displayNameRegex.exec(<string>this.name);

// set name data
if (result?.groups) {
const { firstName, lastName } = result.groups;
return firstName + " " + lastName;
}
},
},
},
virtuals: {},
methods: {
// generateJWT: {
// get() {
Expand All @@ -108,5 +27,5 @@ const UserProfileSchema = new Schema(
);

// exports User model.
const UserProfile = model("UserProfile", UserProfileSchema)
const UserProfile = model("UserProfile", UserProfileSchema);
export default UserProfile;
2 changes: 1 addition & 1 deletion src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const UserSchema = new Schema(
}
},
},
name: {
fullname: {
get() {
const displayNameRegex =
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
Expand Down
15 changes: 8 additions & 7 deletions src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ class Authentication {

// }

async signinWithEmail({ email, accessToken }: { email: Email; accessToken?: string }) {
async signinWithEmail({
email,
accessToken,
}: {
email: Email;
accessToken?: string;
}): Promise<Response<undefined | { token: string }>> {
if (!email)
throw new Error({
status: 400,
Expand All @@ -37,12 +43,7 @@ class Authentication {
try {
const user = await User.findOne({ email });
if (!user) {
// let reg = await register(email);
// res.send({
// ok: true,
// message:
// "Your account has been created, click the link in email to sign in 👻",
// });
// is user cannot be found, then they are not allowed in.
throw new Error({
status: 401,
message:
Expand Down