// CreateUser to create a new user
CreateUser to create a new user
// CreateUser to create a new user
func (UserController) CreateUser(c *gin.Context) {
	user := &models.User{}
	if err := c.BindJSON(user); err != nil {
		c.AbortWithError(http.StatusBadRequest, helpers.ErrorWithCode("invalid_input", "Failed to bind the body data", err))
		return
	}
	user.LastModification = time.Now().Unix()
	err := store.CreateUser(c, user)
	utils.CheckErr(err)
	dbUser, err := store.GetUser(c, params.M{"email": user.Email})
	utils.CheckErr(err)
	encodedKey := []byte(config.GetString(c, "rsa_private"))
	privateKey, err := helpers.GetRSAPrivateKey(encodedKey)
	utils.CheckErr(err)
	token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
		"sub":           "define",
		"userId":        dbUser.ID,
		"userKey":       dbUser.Key,
		"userEmail":     dbUser.Email,
		"userFirstname": dbUser.FirstName,
		"userLastname":  dbUser.LastName,
	})
	tokenStr, err := token.SignedString(privateKey)
	utils.CheckErr(err)
	apiURL := `https://` + config.GetString(c, "front_url") + `/update-account/` + tokenStr
	frontURL := config.GetString(c, "front_url")
	appName := config.GetString(c, "mail_sender_name")
	s := services.GetEmailSender(c)
	err = s.SendActivationEmail(dbUser, apiURL, appName, frontURL)
	if err != nil {
		logrus.Infoln(err)
		c.AbortWithError(http.StatusUnauthorized, helpers.ErrorWithCode("mail_sending_error", "Error when sending mail", err))
		return
	}
	c.JSON(http.StatusCreated, user.Sanitize("", "", ""))
}
func ( UserController ) CreateUser ( c * gin . Context ) { user := & models . User { } if err := c . BindJSON ( user ) ; err != nil { c . AbortWithError ( http . StatusBadRequest , helpers . ErrorWithCode ( " " , " " , err ) ) return } user . LastModification = time . Now ( ) . Unix ( ) err := store . CreateUser ( c , user ) utils . CheckErr ( err ) dbUser , err := store . GetUser ( c , params . M { " " : user . Email } ) utils . CheckErr ( err ) encodedKey := [ ] byte ( config . GetString ( c , " " ) ) privateKey , err := helpers . GetRSAPrivateKey ( encodedKey ) utils . CheckErr ( err ) token := jwt . NewWithClaims ( jwt . SigningMethodRS256 , jwt . MapClaims { " " : " " , " " : dbUser . ID , " " : dbUser . Key , " " : dbUser . Email , " " : dbUser . FirstName , " " : dbUser . LastName , } ) tokenStr , err := token . SignedString ( privateKey ) utils . CheckErr ( err ) apiURL := `https://` + config . GetString ( c , " " ) + `/update-account/` + tokenStr frontURL := config . GetString ( c , " " ) appName := config . GetString ( c , " " ) s := services . GetEmailSender ( c ) err = s . SendActivationEmail ( dbUser , apiURL , appName , frontURL ) if err != nil { logrus . Infoln ( err ) c . AbortWithError ( http . StatusUnauthorized , helpers . ErrorWithCode ( " " , " " , err ) ) return } c . JSON ( http . StatusCreated , user . Sanitize ( " " , " " , " " ) ) }
CreateUser to create a new user
CreateUser to create a new user