Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-12 Thread David Toomey
Yes, that certainly did help. Can't believe I didn't see this and it still 
flew over my head when others pointed it out. 

Looks a bit hacky, but this is the result I came up with (for future 
person's reference): 

(GET  /:profile-page [profile-page]
(if (= (.indexOf profile-page  ) -1)
  (let [profile-page (clojure.string/replace profile-page #-  )]
(let [[{user-profile :handle}] (db/get-users profile-page)]
  (if (not (nil? user-profile))
(layout/page-top
 (str profile-page's Profile Page)
 (profile/profile-page profile-page)))


It's sort of the finishing touches on a relatively complete project. Of 
course, gotta mind those anchors (thanks for that reminder, lest I'd see 
everything blow up). 

Thank you everyone for the time and patience. 

On Monday, March 10, 2014 11:00:32 PM UTC-7, Jarrod Swart wrote:

 No edit button so I have to post again, that first example should end with 
 ;; (make-profile-url John Smith) = /John-Smith

 And to reiterate you decide what your url will look like in your template:

 a href=http://myapp.com/JohnSmith;View John Smith's Profile/a
 or
 a href=http://myapp.com/John-Smith;View John Smith's Profile/a
 or
 a href=http://myapp.com/john-smith;View John Smith's Profile/a

 Then compojure + your route handler respond to the browser requesting the 
 link:

 ;; obviously this is ALL just psedo code of the important elements to give 
 you an idea
 (GET /:username [username] (view-profile-page username)) ;; this route 
 definition will handle any of the above links

 ;; assume you chose the last link type, in stack-overflow style. this 
 means username from the route is john-smith
 (defn view-profile-page [username]
   (let [user (db/get-user-by-username username)]
 (render-template user)))

 (defn get-user-by-username [username]
   (let [no-dash (clojure.string/replace username #-  ) ;; munge 
 username to match what is in DB
  capitalized (capitalize-words no-dash)]
 (select-user-by-name capitalized)))

 So as you can see whatever link or browser request is called, compojure 
 grabs that url param and passes it in.  You then modify that param to fit 
 what you expect and look it up in your DB.  You were essentially working 
 backwards I think.

 Hope that helps!



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread David Toomey
Thanks for the repiles -- and sorry for the delayed reply. I guess I'm 
doing something obnoxiously stupid.

The code I'm working with looks like this: 

  (GET  /:profile-page [profile-page]
   . ;;; check if user is in database, if so, show the profile 
page: ))

I've tried several variations on the theme, but the only thing that doesn't 
throw an error is this: 

(:require [ring.util.codec :as codec)

  (GET (codec/url-encode /:profile-page) [profile-page]

Which does not give the desired result and throws a 404. 

I tried adding it in middleware, converting the arguments to a map, stuff 
like this: 

  (GET (str /:profile-page (codec/url-encode [profile-page]))

At this point, I'm clearly guessing and I fear I did something wrong 
somewhere else. I'm still confused as to why, even after using this, the 
urls do not replace any of the spaces with %20 or anything else. 

It's probably not the least bit surprising that this works without throwing 
a 404, but of course, does not replace the blank spaces:

  (GET (codec/url-decode /:profile-page) [profile-page]

Thanks;
David

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread David Toomey
You should be able to write:

(GET /:profile-page [profile-page] ...)

Compojure (via Clout) automatically decodes parameters in the URL, so there 
shouldn't be any need to decode the data any further.

Heh, I would have thought something was baked in, but I still get urls with 
nothing filling in the blank-space. 

I'm concerned about XXS, but I'm also irritated because the urls look like 
a drooling idiot created my project. I guess the only option is to disallow 
blank spaces in the user names, but this is pretty disappointing. 

Thanks;
David

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread David Toomey


Fair enough. So if I want pretty urls, I have to have an extra column in my 
database then. This is one compromise, but I was hoping for something a 
little more programmatic. 

As a counter to G+, StackOverflow alters the name to lower-case and add a 
'-', so that M User becomes www./m-user.



On Monday, March 10, 2014 9:21:13 PM UTC-7, Jarrod Swart wrote:

 This has become super confusing to follow, possibly because you have the 
 wrong expectation of compojure?

 Compojure is not specificy how your routes will look, it is responding to 
 whatever URLs you put in place.

 In the case of:

 (GET /:profile-page [profile-page] ...)

 :profile-page in the route string, becomes profile-page the variable.

 So if you make the link: http://myapp.com/some user then profile-page 
 will be some user.

 If you make the link: http://myapp.com/SomeUser; then profile-page will 
 be SomeUser.  The route is simply capturing whatever is sent, not 
 specifying or creating anything.  Once you have profile-page you can then 
 modify it as you see fit.

 When you create the links in your app's template you will specify what URL 
 is called, that is when you decide how to display the user's profile name 
 in the URL.  

 I recommend not having a space, take a look at google+ where my username 
 is Jarrod Swart but my profile url is: plus.google.com/+JarrodSwart

 Hopefully this helps, or perhaps I misread the thread.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I'm trying to make proper urls, but I seem to be failing at it.

2014-02-24 Thread David Toomey
I'm building a site and I would like to allow users to create and account, 
and I would like them to have an option to use whitespaces in their handle. 
Apparently I am doing something way wrong here, so it is possible that I 
messed up something somewhere else. 

When I create a user, for example some user, this user name is inserted 
into a database. The site is set up so that users can have profiles. This 
person's profile would be this:

  www.mysite/some user

That is bad. I am hoping to have profile pages look like this: 

 www.mysite/some%20user

or:

  www.mysite/some-user

I attempted to use (url-encode), (url-decode), regex, and all sorts of 
things. Nothing I have tried has worked. 

I'm actually kind of surprised that this isn't baked into Compojure itself, 
but I digress. 

Thanks;

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-05-02 Thread David Toomey
Is this serious? No one knows how to create a login form in Compojure?
I'm seriously confused. I can create accounts, but I can't get the
login part to work. What could I possibly be doing wrong? Is there
anything in my code that indicates something wrong? Is there anything
I could show that could reveal the problem?

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-05-02 Thread David Toomey
I committed the codebase to github. I'm open-sourcing the whole
project anyways, so here is what I have thus far. Since I'm stuck at
the login, the conversion stops there, so this isn't the complete
codebase and basically still a skeleton:

https://github.com/dt1/SoloResume

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-05-02 Thread David Toomey


On May 2, 5:21 am, John D. Hume duelin.mark...@gmail.com wrote:
 On May 2, 2013 2:04 AM, David Toomey dbtoo...@gmail.com wrote:

  Is there anything
  I could show that could reveal the problem?

 Yes, you should have shown the stack trace of the exception (or at least
 the part from the top of the text down to your code).

 But even without that, you have an error coming out of noir.session that
 says something is unbound where an atom was expected. That should send you
 to the source for noir.session. There you'll see everything depends on the
 dynamic global *noir-session*, which is only ever bound by
 wrap-noir-session, which you're not calling. That's a compojure middleware
 fn. Take a look at some compojure tutorial to see where and how they're
 used.

 There are likely other similar middleware fn calls noir will expect you to
 have made. Hopefully having struggled with this one, figuring the others
 out will be easy.

Wow. What an amazing answer.

The stack trace: The main error is the title of this thread. The
second line is something about swap! and clojure.core, the next line
traces directly to the line of code that I pointed out 2 times above.
The next line after that points to a route, which I posted above as
well.

Here is the login code from 4clojure: what middleware and what call
to wrap-noir-session is being used here?

(defn do-login [user pwd]
  (let [user (.toLowerCase user)
{db-pwd :pwd} (from-mongo (fetch-one :users :where {:user
user}))
location (session/get :login-to)]
(if (and db-pwd (.checkPassword (StrongPasswordEncryptor.) pwd
db-pwd))
  (do (update! :users {:user user}
   {:$set {:last-login (java.util.Date.)}}
:upsert false) ; never create new users
accidentally
  (session/put! :user user)
  (session/remove! :login-to)
  (response/redirect (or location /problems)))
  (flash-error /login Error logging in.

Clearly, there is none.

Then you give me a total fuck you answer, Hopefully having struggled
with this one, figuring the others out will be easy.

How is that at all helpful? You tell me to look at the Lib-Noir source
and the source says exactly what I already knew (because, clearly you
are psychic and you know that I didn't look already). Wait... do you
want me to ask Google for a Clojure login page tutorial? Done, do you
know what the first several hits are? My blog which explains how to do
it in Noir. The next few are Stack Overflow threads asking about
creating login pages and this very topic:

This thread, with 4 upvotes is unanswered:
http://stackoverflow.com/questions/14806063/howto-use-lib-noir-stateful-sessions-in-compojure

Four upvotes is quite a lot for a Clojure question. This probably
indicates that this is a broad issue that affects many people. Why?
Because of this shit right here. Clojure is a beautiful language, but
these kind of LOL answers are exactly why the community sucks (I've
read and heard more that a few disturbing complaints) and why people
don't want to learn the language, which is further exacerbated by the
sub-optimal documentation and don't even get me started on the half-
assed tutorials (Look at WHAT middleware tutorial?). If a person just
coming to Clojure is struggling to create something incredibly basic
(hell, IDK, a login page?) and when asked, can't get a civil response,
then the language is toast.

I linked to my github. Does the projects look like the work of someone
that is an utter moron at this language or Lisp in general?

Let me take this moment to help you: the correct way to answer the
question is to direct me to a *reputable* source that touches on this
issue, and maybe just maybe accept the retarded idea that I showed you
EXACTLY where the stacktraces pointed (which I did). If all else
fails, you can even tell me the answer or at least try to answer it in
a way that isn't utterly condescending or act like you can't look at 5
LOC and not comprehend that error on this line means error on
this line. Clearly, I don't see what the issue is and I am asking for
help to see where my logic is wrong: I'm not asking you to be an ass.

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-05-02 Thread David Toomey


On May 2, 7:59 am, John D. Hume duelin.mark...@gmail.com wrote:
 I've never used noir and have barely used 4clojure, but both of them
 apparently do hidden global things that make it hard to know the context in
 which your code is running. Your app needs to be wrapped in noir's
 `wrap-noir-session` middleware in much the same way this blog post shows
 Ring's `wrap-session` being used:

 http://rjevans.net/post/2628238502/session-support-in-compojure-ringhttps://gist.github.com/mirrormatch/768768

 I'll leave it at that.

Cool, thanks.

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-04-30 Thread David Toomey
Hello, I am trying to get a login form to work in Compojure. I had 
originally written this app in Noir, but now I'm trying to move it off of 
Noir. I am now using Lib-Noir and the (noir.session) namespace doesn't seem 
to be working the same way as Noir. I'm now confused. 

The error, as mentioned in the title: 
java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to 
clojure.lang.Atom


Here is the code that appears to be getting mucked up: 

(defn do-login [handle passwd]
  (let [tuser (select db/allusers
  (fields :username :password :usertype)
  (where {:username newguy}))]
(if (crypt/compare password 
   (let [[{pwd :password}] tuser]
 pwd))
  ;; error on this line: 
  (do (sesh/put! :uname handle)
  (response/redirect /))
  (response/redirect /

and the route:

  (GET /account-login [] (homes/login-page))
  (POST /account-login {{:strs [handle passwd]} :params}
(log/do-login handle passwd))

Basically, except for the silly let-binding above, I'm following the 
pattern found in 4clojure. 



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Lib-Noir session error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-04-30 Thread David Toomey
Hello, I am trying to get a login form to work in Compojure. I had 
originally written this app in Noir, but now I'm trying to move it off of 
Noir. I am now using Lib-Noir and the (noir.session) namespace doesn't seem 
to be working the same way as Noir. I'm now confused. 

The error, as mentioned in the title: 
java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to 
clojure.lang.Atom


Here is the code that appears to be getting mucked up: 

(defn do-login [handle passwd]
  (let [tuser (select db/allusers
  (fields :username :password :usertype)
  (where {:username newguy}))]
(if (crypt/compare password 
   (let [[{pwd :password}] tuser]
 pwd))
  ;; error on this line: 
  (do (sesh/put! :uname handle)
  (response/redirect /))
  (response/redirect /

and the route:

  (GET /account-login [] (homes/login-page))
  (POST /account-login {{:strs [handle passwd]} :params}
(log/do-login handle passwd))


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-04-30 Thread David Toomey


On Tuesday, April 30, 2013 6:25:11 AM UTC-7, Tassilo Horn wrote:

 David Toomey dbto...@gmail.com javascript: writes: 

 Hi David, 

  The error, as mentioned in the title: java.lang.ClassCastException: 
  clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom 

 In which line? 

 The error is where the bolded is. It may have been confusing on the OP 
because I accidentally posted the test-case on not the real code: 

(defn do-login [handle passwd]
  (let [tuser (select db/allusers
  (fields :username :password :usertype)
  (where {:username handle}))]
(if (crypt/compare passwd
   (let [[{pwd :password}] tuser]
 pwd))
  ;ERROR:
  (do *(sesh/put! :uname handle)*
  (response/redirect /))
  (response/redirect /
 

 Hm, the message tells that you are using an atom function like swap! on 
 something that's not an Atom but Unbound.  But your code doesn't contain 
 such a coll.  So I guess it's in the SQL Korma code here 
 where db/allusers is Unbound. 


No, that part and the bcrypt comparision passes. Regardless, Korma does not 
use atoms. The problem is with the noir.session namespace and the error 
revolves around (sesh/put!). As I understand it, the noir.session namespace 
uses an atom. 


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

2013-04-30 Thread David Toomey
To clarify, I was suspecting that I did something wrong in the (POST)
route. I tried using (:syms) as well as (:strs). I'm really stuck on
what is happening here.

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.