simplify code
This commit is contained in:
3 files changed
+9
-20
No files matched your search
@@ -72,7 +72,7 @@ func CreateDefaultAdmin() models.Admin {
|
|||||||
var aid string
|
var aid string
|
||||||
for {
|
for {
|
||||||
aid = GenerateID(6)
|
aid = GenerateID(6)
|
||||||
if ValidateID(aid, 3) == true {
|
if ValidateID(aid, 3) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,9 +113,6 @@ func NewSystem() {
|
|||||||
|
|
||||||
var SecretKey = os.Getenv("secret")
|
var SecretKey = os.Getenv("secret")
|
||||||
|
|
||||||
var systemEmail string = os.Getenv("SYSTEM_EMAIL")
|
|
||||||
var systemPassword string = os.Getenv("SYSTEM_PASSWORD")
|
|
||||||
|
|
||||||
func AuthenticateUser(c *fiber.Ctx, userType int) (bool, string) {
|
func AuthenticateUser(c *fiber.Ctx, userType int) (bool, string) {
|
||||||
if userType < 1 || userType > 3 {
|
if userType < 1 || userType > 3 {
|
||||||
log.Fatal("Invalid userType")
|
log.Fatal("Invalid userType")
|
||||||
@@ -240,7 +237,7 @@ func Enroll(c *fiber.Ctx) error {
|
|||||||
var sid string
|
var sid string
|
||||||
for {
|
for {
|
||||||
sid = GenerateID(6)
|
sid = GenerateID(6)
|
||||||
if ValidateID(sid, 1) == true {
|
if ValidateID(sid, 1) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +258,7 @@ func Enroll(c *fiber.Ctx) error {
|
|||||||
var pen string
|
var pen string
|
||||||
for {
|
for {
|
||||||
pen = GenerateID(9)
|
pen = GenerateID(9)
|
||||||
if ValidatePEN(pen) == true {
|
if ValidatePEN(pen) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,8 +384,7 @@ func RegisterTeacher(c *fiber.Ctx) error {
|
|||||||
// For the unlikely event that an ID is already in use this will simply try again till it gets a id not in use
|
// For the unlikely event that an ID is already in use this will simply try again till it gets a id not in use
|
||||||
for {
|
for {
|
||||||
tid = GenerateID(6)
|
tid = GenerateID(6)
|
||||||
isValid := ValidateID(tid, 2)
|
if ValidateID(tid, 2) {
|
||||||
if isValid == true {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -485,7 +481,7 @@ func CreateAdmin(c *fiber.Ctx) error {
|
|||||||
var aid string
|
var aid string
|
||||||
for {
|
for {
|
||||||
aid = GenerateID(6)
|
aid = GenerateID(6)
|
||||||
if ValidateID(aid, 3) == true {
|
if ValidateID(aid, 3) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -733,7 +729,7 @@ func TeacherLogin(c *fiber.Ctx) error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var verified bool = teacher.ComparePasswords(data["password"])
|
var verified bool = teacher.ComparePasswords(data["password"])
|
||||||
if verified == false {
|
if !verified {
|
||||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "incorrect password",
|
"message": "incorrect password",
|
||||||
@@ -803,7 +799,7 @@ func AdminLogin(c *fiber.Ctx) error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var verified bool = admin.ComparePasswords(data["password"])
|
var verified bool = admin.ComparePasswords(data["password"])
|
||||||
if verified == false {
|
if !verified {
|
||||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "incorrect password",
|
"message": "incorrect password",
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ var config Config = Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
from string
|
|
||||||
to []string
|
to []string
|
||||||
subject string
|
subject string
|
||||||
body string
|
body string
|
||||||
|
|||||||
@@ -29,10 +29,7 @@ func ValidateID(id string, userType int) bool { // true: valid id, false: id alr
|
|||||||
newID.ParentType = userType
|
newID.ParentType = userType
|
||||||
newID.ID = primitive.NewObjectID()
|
newID.ID = primitive.NewObjectID()
|
||||||
_, insertErr := idCollection.InsertOne(context.Background(), newID)
|
_, insertErr := idCollection.InsertOne(context.Background(), newID)
|
||||||
if insertErr != nil {
|
return insertErr == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -42,10 +39,7 @@ func ValidatePEN(pen string) bool { // true: valid pen, false: pen already in us
|
|||||||
var foundID models.Id
|
var foundID models.Id
|
||||||
err := studentCollection.FindOne(ctx, bson.M{"schooldata.pen": pen}).Decode(&foundID)
|
err := studentCollection.FindOne(ctx, bson.M{"schooldata.pen": pen}).Decode(&foundID)
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
return err != nil
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateID(length int) string {
|
func GenerateID(length int) string {
|
||||||
|
|||||||
Reference in new issue
Block a user