Ejemplo n.º 1
0
func UsersAuthenticateHandler(c echo.Context) error {
	session := session.NewSession(c)

	request_params := session.GetParam("request").(map[string]interface{})
	user_params := request_params["user"].(map[string]interface{})

	valid := false
	user := model.User{}

	if user_params["email"] != nil && user_params["password"] != nil {
		email := user_params["email"].(string)
		password := user_params["password"].(string)

		user = session.GetApplication().FindUserByEmail(email)
		valid = user.VerifyPassword(password)
	} else if user_params["facebook_id"] != nil && user_params["facebook_token"] != nil {
		facebook_id := user_params["facebook_id"].(string)
		facebook_token := user_params["facebook_token"].(string)

		user = session.GetApplication().FindUserByFacebookId(facebook_id)
		valid = user.VerifyFacebookToken(facebook_token)
	} else if user_params["transfer_id"] != nil && user_params["transfer_token"] != nil {
		user_id := user_params["transfer_id"].(string)
		transfer_token := user_params["transfer_token"].(string)

		user = session.GetApplication().FindUserByTransferId(user_id)

		valid = user.VerifyTransferToken(transfer_token)
	}

	if !valid || user.Id == bson.ObjectId("") {
		session.SetError(1101)
	} else {
		user.NewSession()
		session.SetRecords("users", []interface{}{user})
	}
	session.Write()

	return nil
}
Ejemplo n.º 2
0
func UsersCreateHandler(c echo.Context) error {
	session := session.NewSession(c)

	request_params := session.GetParam("request").(map[string]interface{})
	user_params := request_params["user"].(map[string]interface{})

	user := model.User{}
	user.ApplicationId = bson.ObjectIdHex(session.GetParam("application_id").(string))

	email := strings.ToLower(user_params["email"].(string))

	if user_params["name"] != nil && user_params["email"] != nil && user_params["facebook_id"] == nil {
		user.Name = user_params["name"].(string)
		user.Email = email
		user.SetPassword(user_params["password"].(string))
	} else {
		user.Name = user_params["name"].(string)
		user.Email = email
		user.FacebookId = user_params["facebook_id"].(string)

		if user_params["password"] != nil {
			user.SetPassword(user_params["password"].(string))
		}

	}

	err := user.Save()

	if err {
		logger.Error("1105" + user.Id.Hex())
		session.SetError(1105)
	} else {
		user.NewSession()
		logger.Error("Registered User: "******"users", []interface{}{user})
	}
	session.Write()

	return nil
}