-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG/Feature] MVC Dependency authentication example #1536
Comments
Each Controller's method creates a new route, so two controllers can't share the same route with the current implementation. If I am going to change the MVC again, the v12.2.0 release will be delayed even more, I will think of it and come back to you with a solution. |
Thanks for the feedback. I look forward to your proposed solution. |
Hello @Dexus, I did it without any changes (however you could do it by checking the Authenticated integer value ( iris/_examples/mvc/authenticated-controller/main.go Lines 27 to 32 in abd6ed4
iris/_examples/mvc/authenticated-controller/main.go Lines 54 to 68 in abd6ed4
iris/_examples/mvc/authenticated-controller/main.go Lines 41 to 42 in abd6ed4
iris/_examples/mvc/authenticated-controller/main.go Lines 73 to 77 in abd6ed4
iris/_examples/mvc/authenticated-controller/main.go Lines 102 to 108 in abd6ed4
|
Hi @kataras, thank you, it works perfectly, just as I imagined it would. That makes things a lot easier now. |
I am glad it helped, do you think it would be easier to default this rule on mvc apps? |
That's a good question. I think it always depends on the use case. If I just relate it to my work and the projects I've done in the past, it might fit quite well as a default. Just for websites with frontend I would prefer it as default. For API Entpoints, it does not always make sense. I think a warning with debug might be helpful there depending on the setting of the SetRegisterRule. So you know why a route was not registered, but that's just a thought that would help me, because I had the problem ;) |
Yes, now this new route registration rule is described in the example too. The |
I think that's good. It's so right for me. |
Hi @kataras while i code for the certification, i found a crazy problem
Here a bit code:
Do you know what is happening here? |
Hello @Dexus, Thanks for the report! It should be fixed, update to the master one. |
@kataras |
@kataras |
Hello @Dexus, The
app := iris.New()
app.ConfigureContainer(func(api *iris.APIContainer){
api.RegisterDependency(%yourdep%)
// [...]
})
m := mvc.New(app /* or any other iris.Party */)
m.Handle(new(myController))
// no need to m.Register the %yourdep%,
// it's inherited from the target party (the root app in this case)
// The %yourdep% dependency is registered to that mvc Application
// and its controllers automatically as well.
m2 := mvc.New(app.Party("/user"))
m2.Handle(new(userController))
// [...] |
Thanks for the reminder. I don't know why I forgot that again, use it in a project like this. |
No worries @Dexus, you can also check the database/mysql new example for some kind of "help" as well. Also, I have just pushed another new cool feature: versioned controllers, example at: https://github.com/kataras/iris/tree/master/_examples/mvc/versioned-controller |
Thats a very cool feature! |
Yes @Dexus! I've added another example that may be helpful for you as well: https://github.com/kataras/iris/tree/master/_examples/mvc/overview +-------------------+
| Env (DEV, PROD) |
+---------+---------+
| | |
| | |
| | |
DEV | | | PROD
-------------------+---------------------+ | +----------------------+-------------------
| | |
| | |
+---+-----+ +----------------v------------------+ +----+----+
| sqlite | | NewDB(Env) DB | | mysql |
+---+-----+ +----------------+---+--------------+ +----+----+
| | | |
| | | |
| | | |
+------------+-----+ +-------------------v---v-----------------+ +----+------+
| greeterWithLog | | NewGreetService(Env, DB) GreetService | | greeter |
-------------+-----+ +---------------------------+-------------+ +----+------+
| | |
| | |
| +-----------------------------------------+ |
| | GreetController | | |
| | | | |
| | - Service GreetService <-- | |
| | | |
| +-------------------+---------------------+ |
| | |
| | |
| | |
| +-----------+-----------+ |
| | HTTP Request | |
| +-----------------------+ |
| | /greet?name=kataras | |
| +-----------+-----------+ |
| | |
+------------------+--------+ +------------+------------+ +-------+------------------+
| model.Response (JSON) | | Response (JSON, error) | | Bad Request |
+---------------------------+ +-------------------------+ +--------------------------+
| { | | mysql: not implemented |
| "msg": "Hello kataras" | +--------------------------+
| } |
+---------------------------+ |
Former-commit-id: 2b5523ff3e2aab60dd83faa3c520b16a34916fbe
rel to: #1536 too Former-commit-id: 0ed36644ee2d6c27d90450700d9241eb1ba93c17
Describe the bug
on the master branch "https://github.com/kataras/iris/blob/master/_examples/mvc/authenticated-controller/main.go" an authentication is used to show how it is done when you search for an authenticated user.
But how can I find an unauthenticated user who can call the same route but from a different controller?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Let's take two controllers that are both registered for the same route, but one of them has no authentication feature. Now when I call the route, I want the call without authentication to return a different value than if I were authenticated.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
I don't think it's a bug, but a feature request, although I think others do as well, that the same route should call a different controller under different circumstances.
The text was updated successfully, but these errors were encountered: