digitalmars.D.learn - How to return user name from vibed session?
- Suliman (12/12) Dec 10 2015 Vibed have method get for user session
- Adrian Matoga (3/15) Dec 10 2015 I think what you need is Session.get, not SessionStore.get:
- Suliman (3/22) Dec 10 2015 Give me example please
- Suliman (21/45) Dec 10 2015 I found example in vibenews:
- Suliman (18/18) Dec 10 2015 Oh, my issue. Right variant of setting session is:
- Mike Parker (8/11) Dec 10 2015 When you have a template that looks like this:
- Suliman (4/19) Dec 10 2015 So why for set both variant are work?
- Suliman (2/24) Dec 10 2015 because set return void, and get return T?
- Mike Parker (20/21) Dec 10 2015 No, it has nothing to do with the return type declarations. It's
Vibed have method get for user session http://vibed.org/api/vibe.http.session/SessionStore I set user name for session like this: req.session.set("username", "admin"); But I can't understand how to get user name from it: abstract std.variant.VariantN!(20) get( string id, string name, lazy std.variant.VariantN!(20) defaultVal ); What does every string here mean? Could anybody to show example of usage?
Dec 10 2015
On Thursday, 10 December 2015 at 11:36:20 UTC, Suliman wrote:Vibed have method get for user session http://vibed.org/api/vibe.http.session/SessionStore I set user name for session like this: req.session.set("username", "admin"); But I can't understand how to get user name from it: abstract std.variant.VariantN!(20) get( string id, string name, lazy std.variant.VariantN!(20) defaultVal ); What does every string here mean? Could anybody to show example of usage?I think what you need is Session.get, not SessionStore.get: http://vibed.org/api/vibe.http.session/Session.get
Dec 10 2015
On Thursday, 10 December 2015 at 12:21:40 UTC, Adrian Matoga wrote:On Thursday, 10 December 2015 at 11:36:20 UTC, Suliman wrote:Give me example pleaseVibed have method get for user session http://vibed.org/api/vibe.http.session/SessionStore I set user name for session like this: req.session.set("username", "admin"); But I can't understand how to get user name from it: abstract std.variant.VariantN!(20) get( string id, string name, lazy std.variant.VariantN!(20) defaultVal ); What does every string here mean? Could anybody to show example of usage?I think what you need is Session.get, not SessionStore.get: http://vibed.org/api/vibe.http.session/Session.get
Dec 10 2015
On Thursday, 10 December 2015 at 12:30:51 UTC, Suliman wrote:On Thursday, 10 December 2015 at 12:21:40 UTC, Adrian Matoga wrote:I found example in vibenews: writeln("USER Session: ", req.session.get!string("username")); but I can't understand why I should call it like this, but not like writeln("USER Session: ", req.session.get("username")); And it's look like it do not return username, or user name are set incorrectly: if(dbuser == "admin") // admin name hardcoded { _auth.isAuthorizated = true; req.session.set("username", "admin"); } else { req.session.set(request["username"].to!string, dbuser); //set current username in parameter of session name writeln("user name is: ", dbuser); }On Thursday, 10 December 2015 at 11:36:20 UTC, Suliman wrote:Give me example pleaseVibed have method get for user session http://vibed.org/api/vibe.http.session/SessionStore I set user name for session like this: req.session.set("username", "admin"); But I can't understand how to get user name from it: abstract std.variant.VariantN!(20) get( string id, string name, lazy std.variant.VariantN!(20) defaultVal ); What does every string here mean? Could anybody to show example of usage?I think what you need is Session.get, not SessionStore.get: http://vibed.org/api/vibe.http.session/Session.get
Dec 10 2015
Oh, my issue. Right variant of setting session is: if(dbuser == "admin") // admin name hardcoded { _auth.isAuthorizated = true; req.session.set("username", "admin"); } else { req.session.set("username", dbuser); //set current username in parameter of session name writeln("username from req: ", request["username"].to!string); writeln("user name is: ", dbuser); writeln(request["username"].to!string, " == ", dbuser); } But question about why I need to get session info like: writeln("USER Session: ", req.session.get!string("username")); is still actual.
Dec 10 2015
On Thursday, 10 December 2015 at 13:23:29 UTC, Suliman wrote:But question about why I need to get session info like: writeln("USER Session: ", req.session.get!string("username")); is still actual.When you have a template that looks like this: V get(V, K)(K key) {...} The compiler is able to deduce the type of K because of the argument 'key'. However, there's no way for it to know what V should be. You have to tell it explicitly when you instantiate it: auto str = get!string("key1"); auto i = get!int("key2");
Dec 10 2015
On Thursday, 10 December 2015 at 13:34:02 UTC, Mike Parker wrote:On Thursday, 10 December 2015 at 13:23:29 UTC, Suliman wrote:So why for set both variant are work? req.session.set("username", "admin"); req.session.set!string("username", "admin");But question about why I need to get session info like: writeln("USER Session: ", req.session.get!string("username")); is still actual.When you have a template that looks like this: V get(V, K)(K key) {...} The compiler is able to deduce the type of K because of the argument 'key'. However, there's no way for it to know what V should be. You have to tell it explicitly when you instantiate it: auto str = get!string("key1"); auto i = get!int("key2");
Dec 10 2015
On Thursday, 10 December 2015 at 13:43:58 UTC, Suliman wrote:On Thursday, 10 December 2015 at 13:34:02 UTC, Mike Parker wrote:because set return void, and get return T?On Thursday, 10 December 2015 at 13:23:29 UTC, Suliman wrote:But question about why I need to get session info like: writeln("USER Session: ", req.session.get!string("username")); is still actual.When you have a template that looks like this: V get(V, K)(K key) {...} The compiler is able to deduce the type of K because of the argument 'key'. However, there's no way for it to know what V should be. You have to tell it explicitly when you instantiate it: auto str = get!string("key1"); auto i = get!int("key2");
Dec 10 2015
On Thursday, 10 December 2015 at 13:46:19 UTC, Suliman wrote:because set return void, and get return T?No, it has nothing to do with the return type declarations. It's about whether or not the compiler has enough information to deduce the types. V get(V, K)(K key, V defaultVal); auto i = 10; i = get("key", i); This works because the compiler sees that you have given it a string where it expects a K and an int where it expects a V, so it knows that K = string and V = int. On the other hand: V get(V, K)(K key); auto i = get("key"); What type is this supposed to return? Even if you do this: int i = get("key"); Obviously, the compiler knows that i is int, but that plays no role in template type deduction. Only the template declaration and instantiation do. So we have to explicitly tell the compiler what type V should be in this case by passing the type as a template argument. auto i = get!int("key");
Dec 10 2015