//RegisterUser ... Register a new user by creating his record as a Person and also as a user. //If Contact is not attached to a person, extract it from user detail and create a contact object func (usrlogic *UserLogic) RegisterUser(person models.Person, user models.User) (interface{}, interface{}, error) { var err error restfulds := dataaccess.RESTFul{} contact := models.Contacts{} if len(person.Contacts) == 0 { contact.Email = user.Email contact.PhoneNo = user.PhoneNum } person.Contacts = append(person.Contacts, contact) restfulds.ServiceURI = usrlogic.ServiceList["utility"] restfulds.Logger = usrlogic.Logger savedEntity, statusCode, err := restfulds.SaveObject(person, "person") if statusCode != 0 { return nil, nil, err } savedPerson := savedEntity.(map[string]interface{}) restfulds.ServiceURI = usrlogic.ServiceList["auth"] user.PersonID = int(savedPerson["ID"].(float64)) user.Verificationtoken = utility.RandStr(6, "number") user.BaseModel.Status = "UNACTIVATED" user.Emailverified = true savedEntity, statusCode, err = restfulds.SaveObject(user, "user") if statusCode != 0 { //Revert the person saved usrlogic.Logger.Crit(err.Error()) restfulds.ServiceURI = usrlogic.ServiceList["utility"] _ = restfulds.DeleteObject("person/" + strconv.Itoa(user.PersonID)) return nil, nil, err } savedUser := savedEntity.(map[string]interface{}) return savedPerson, savedUser, nil }
func (backend *JWTAuthenticationBackend) Authenticate(user *util.User, password string) bool { //hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(password), 10) /*testUser := util.User{ UUID: uuid.New(), Username: user.Username, Password: string(hashedPassword), }*/ user.UUID = uuid.New() //fmt.Println(bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(hashedPassword))) fmt.Println(password) fmt.Println(user.Password) err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) if err != nil { fmt.Println(err.Error()) return false } return true }