Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  before_call/2

Guest
Posted: Sun Oct 26, 2008 4:52 am Reply with quote
Guest
Hi guys

Does anyone have an example of how to use before_call to check if a
user is logged in assuming that we use sessions to track logged in
users? I am in a bit of trouble trying to get this to work. I have
something like below:

before_call(is_logged_in, A) ->
{is_logged_in, [A]}.

is_logged_in([A]) ->
case utilman:check_cookie(A) of
{ok, Sess} ->
% do something
_ ->
% do something
end.

I get a long error trace when I try to access a function in the
controller:

Reason: {undef,
[{dashboard_controller,before_call,
[index,
[{arg,#Port<0.5879>,
{{127,0,0,1},60507},
{headers,"keep-alive",
....

Does anyone know how to make this work?

Thanks
Nii AMon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Sun Oct 26, 2008 10:57 am Reply with quote
Guest
It appears that I needed to include the before_call/2 in the list of
exported functions. That takes care of the previous problem.

However I have come up with a new problem. So now I have this:

before_call(is_logged_in, A) ->
io:format("hello. I see you").

just to test to see if the call would be made right. I end up with
this error:

ERROR erlang code crashed:
File: appmod:0
Reason: {function_clause,
[{dashboard_controller,before_call,
[index,
[{arg,#Port<0.7415>,
{{127,0,0,1},49695},
{headers,"keep-alive",
"text/xml,application/xml,application/xhtml
+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
"localhost:
8057",undefined,undefined,undefined,
undefined,undefined,undefined,undefined,
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X;
en) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/
523.12.2",
undefined,
...

From what I see, this means that no function clause matched the
incoming function signature. Has anyone used before_call/2
successfully?

Thanks
Nii AMon

On Oct 26, 4:52
dmitriid
Posted: Mon Oct 27, 2008 12:04 pm Reply with quote
User Joined: 17 Aug 2006 Posts: 213
On Oct 26, 2008, at 12:57 PM, nii amon wrote:

>
> It appears that I needed to include the before_call/2 in the list of
> exported functions. That takes care of the previous problem.
>
> However I have come up with a new problem. So now I have this:
>
> before_call(is_logged_in, A) ->
> io:format("hello. I see you").
>
> just to test to see if the call would be made right. I end up with
> this error:

I believe this should be something like this:

-export([before_call/2]).

before_call(is_logged_in, A) ->
io:format("hello"),
{is_logged_in, A};
before_call(Func, A) ->
{Func, A}.

because we need to return {NewFuncName::atom(), NewParams::[term()]}
from this function


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
View user's profile Send private message
Guest
Posted: Mon Oct 27, 2008 8:44 pm Reply with quote
Guest
Thanks man.

Do you know if there is anything more I have to do: I have a trace
statement put in the execution of before_call/2 but I don't see it
being printed in the console and it does not appear to redirect to the
URL I point it to. I don't think it works at all.

I think we should all work towards a wiki for erlyweb so that people
who have done stuff like this sort of stuff before would be able to
document it. But as it stands, even for the simplest things, it seems
you have to go through a lot of effort due to inadequate
documentation.

On Oct 27, 12:04
dmitriid
Posted: Tue Oct 28, 2008 10:16 am Reply with quote
User Joined: 17 Aug 2006 Posts: 213
Hm.... What I always do, is I start yaws in intractive mode (yaws -i or sudo yaws -i) and then do all the erlyweb stuff from there. Then I see all the io:format messages just fine

How do you attempt to do the redirect? Since before_call should return a tuple in the form of {NewFunc, Params}, a redirect to a different function may probably look like this (this is untested, so there could be mistakes):

-compile(export_all).

before_call(call_1, A) ->
    {new_func, A};           %% substitute function, no visible redirect
before_call(call_2, A) ->
    {call_2, A};             %% call the actual function,
                             %%let the function do a redirect
before_call(call_3, A) ->
    {new_func_3, A}.         %% call a substtute function,
                             %% let it do a redirect,
                             %% same as above, with a new name

new_func(A) ->
    do_some_stuff,
    {data, ok}.

call_2(A) ->
    {ewr, some_controller}.

new_func_3(A) ->
    {ewr, some_other_controller}.



As for a wiki, that'd be grand Smile The only problem is that it should really be an Erlang-based wiki to show off the ErlyWeb... Or, probaby, some interim wiki...

Quote:
Thanks man. Do you know if there is anything more I have to do: I have a trace statement put in the execution of before_call/2 but I don't see it being printed in the console and it does not appear to redirect to the URL I point it to. I don't think it works at all. I think we should all work towards a wiki for erlyweb so that people who have done stuff like this sort of stuff before would be able to document it. But as it stands, even for the simplest things, it seems you have to go through a lot of effort due to inadequate documentation. On Oct 27, 12:04�pm, Dmitrii Dimandt <dmitr...@gmail.com> (dmitr...@gmail.com) wrote: [/code]
Quote:
On Oct 26, 2008, at 12:57 PM, nii amon wrote: [/code]
Quote:
It appears that I needed to include the before_call/2 in the list of exported functions. That takes care of the previous problem. [/code]
Quote:
However I have come up with a new problem. So now I have this: [/code]
Quote:
before_call(is_logged_in, A) -> � � � �io:format("hello. I see you"). [/code]
Quote:
just to test to see if the call would be made right. I end up with this error: [/code]
I believe this should be something like this: -export([before_call/2]). before_call(is_logged_in, A) -> � � �io:format("hello"), � � �{is_logged_in, A}; before_call(Func, A) -> � � �{Func, A}. because we need to return {NewFuncName::atom(), NewParams::[term()]} � from this function [/code]
[/code]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
View user's profile Send private message
Guest
Posted: Thu Oct 30, 2008 4:15 pm Reply with quote
Guest
Thanks for the response.

Yes I agree, the Wiki should be erlang-based. But in the interim we
can really use something that is not till we have one. Do you know of
any open source erlang Wikis out there?

On Oct 28, 10:15
Guest
Posted: Thu Oct 30, 2008 5:43 pm Reply with quote
Guest
Hei, how about this: http://www.sics.se/~joe/tutorials/wiki/wiki.html?

On Oct 28, 10:15
dmitriid
Posted: Tue Nov 04, 2008 12:28 pm Reply with quote
User Joined: 17 Aug 2006 Posts: 213
There are plenty.

Wikipedia's Mediawiki, <http://www.mediawiki.org/wiki/MediaWiki>, and PM
Wiki, <http://www.pmwiki.org/>, are two wikis I've used myself. There are
more: <http://en.wikipedia.org/wiki/Comparison_of_wiki_software>

Each wiki has it' strengths and weaknesses, of course


--On October 30, 2008 9:14:59 AM -0700 nii amon <jazzyy@gmail.com> wrote:

>
> Thanks for the response.
>
> Yes I agree, the Wiki should be erlang-based. But in the interim we
> can really use something that is not till we have one. Do you know of
> any open source erlang Wikis out there?
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
View user's profile Send private message
Guest
Posted: Tue Nov 04, 2008 4:19 pm Reply with quote
Guest
Ok we are spoilt for choice. Why don't we just choose one and host it?
I don't have server space but if someone donates the space I would not
mind doing the deploy.

On Nov 4, 7:37
wailian
Posted: Tue Mar 20, 2012 2:40 am Reply with quote
Guest
The shoes absolutely are an avant-garde day time day admiration and do amazing problems even although access just about any apparel! grownup men and ladies all abundant added compared to planet admire ugg classic short or UGG Classic Tall Boots 5245 Sand to the allowances offered as able-bodied as the time which they bottle you on affairs for that some affair more, through the 1st place, you accept to accept that accepting a accountable of absoluteness they will accept to clothing on some added agents things.

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum