update/better-logic
This commit is contained in:
1 parent
592cedc276
commit
325c842230
4 files changed
+59
-26
No files matched your search
@@ -16,6 +16,7 @@ type Admin struct {
|
||||
FirstName string `json:"firstname" validate:"required"`
|
||||
LastName string `json:"lastname" validate:"required"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
SchoolEmail string `json:"schoolemail"`
|
||||
Password string `json:"-" validate:"min=10,max=32"`
|
||||
TempPassword bool `json:"temppassword"`
|
||||
AID string `json:"aid"`
|
||||
@@ -23,6 +24,12 @@ type Admin struct {
|
||||
Updated_at time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (a *Admin) GenerateSchoolEmail() string {
|
||||
var email string = strings.ToLower(a.LastName) + "_" + strings.ToLower(string(a.FirstName[0])) + "@surreyschools.ca"
|
||||
// Add check to see if email already exists
|
||||
return email
|
||||
}
|
||||
|
||||
func (s *Admin) HashPassword(password string) string {
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte(password), 14)
|
||||
return string(hash)
|
||||
|
||||
+15
-2
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"school-management/database"
|
||||
"strings"
|
||||
@@ -9,11 +10,13 @@ import (
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
var lockerCollection *mongo.Collection = database.OpenCollection(database.Client, "lockers")
|
||||
var studentCollection *mongo.Collection = database.OpenCollection(database.Client, "students")
|
||||
|
||||
type Student struct {
|
||||
ID primitive.ObjectID `bson:"_id"`
|
||||
@@ -56,9 +59,19 @@ func (s *Student) HashPassword(password string) string {
|
||||
return string(hash)
|
||||
}
|
||||
|
||||
func (s *Student) GenerateSchoolEmail() string {
|
||||
func (s *Student) EmailExists(email string) bool {
|
||||
findErr := studentCollection.FindOne(context.TODO(), bson.M{"schooldata.schoolemail": email})
|
||||
if findErr != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Student) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||
var email string = strings.ToLower(string(s.PersonalData.FirstName[0])) + "." + strings.ToLower(s.PersonalData.LastName) + "@surreyschools.ca"
|
||||
// Add check to see if email already exists
|
||||
if offset > 0 {
|
||||
email = lastEmail[:offset] + string(s.PersonalData.FirstName[offset]) + lastEmail[offset:]
|
||||
}
|
||||
return email
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ func (t *Teacher) HashPassword(password string) string {
|
||||
}
|
||||
|
||||
func (t *Teacher) GenerateSchoolEmail() string {
|
||||
var email string = strings.ToLower(string(t.FirstName[0])) + "_" + strings.ToLower(t.LastName) + "@surreyschools.ca"
|
||||
// Add check to see if email already exists
|
||||
var email string = strings.ToLower(t.LastName) + "_" + strings.ToLower(string(t.FirstName[0])) + "@surreyschools.ca"
|
||||
return email
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user