ruby sinatra admin login rack--two way

http://www.sinatrarb.com/faq.html require 'sinatra' helpers do def protected! return if authorized? headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"' halt 401, "Not authorized\n" end def authorized? @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == ['admin', 'admin'] end end get '/' do "Everybody can see this page" end get '/protected' do protected! "Welcome, authenticated client" end http://www.highdots.com/forums/ruby-rails-talk/logging-out-rake-auth-basic-284054.html LOGIN FORM (GET LOGIN METHOD) <form method="post" action="/login"> <p><label>Username</label><input name="post[username]" /></p> <p><label>Password</label><input name="post[password]" type="password"/></p> <p><button type="submit">Login</button></p> </form> POST LOGIN METHOD post '/login' do if authenticate(params["post"]["username"], Digest::MD5.hexdigest(params["post"]["password"])) session[:user] = params["post"]["username"] flash[:notice] = "Login succeeded!" redirect '/admin' else flash[:error] = "Login failed!" redirect '/login' end end HELPER METHODS # Authentication is hard-coded as there will only 1-3 users def authenticate(username, password) if username == 'admin' and password == '[admin_password_in_MD5]' return true else return false end end # Protect pages def login_required if session[:user] return true else redirect '/login' return false end end # Get the username of the logged in user def current_user if session[:user] session[:user] end end # Verify if a user is logged in def logged_in? !!session[:user] end

2014-09-25 · 1 min · 173 words · Me

jQuery Mobile and AngularJS Working Together

http://simonguest.com/2013/04/08/jquery-mobile-and-angularjs-working-together/ http://0not.net/index.php/using-angularjs-and-jquery-mobile/ At the bottom of body, load AngularJS and then jQM Use jQM for routing (which is the default, as long as you don’t include ngRoute)

2014-09-21 · 1 min · 27 words · Me

StrongLoop begin

http://docs.strongloop.com/display/LB/LoopBack+2.0+release+notes http://docs.strongloop.com/display/LB/Project+layout+reference http://docs.strongloop.com/pages/viewpage.action?pageId=3836281 https://github.com/strongloop/loopback-example-app this is new loopback example, need to look at this example, can understand how to work loopback. if see “slc lb”, the mean is old loopback 1.0, so don’t need to see. https://github.com/strongloop/loopback-example-passport http://passportjs.org/guide/oauth/ I try many, so now I think loopback 2.0….is too new, many docs is not correct. Maybe furture is good or ok, but now for develpoer is no good….

2014-09-15 · 1 min · 67 words · Me

StrongLoop Access Control

x http://docs.strongloop.com/display/LB/Controlling+data+access x can’t use old…https://github.com/strongloop/loopback-example-access-contro ……………..l Ok http://docs.strongloop.com/display/LB/Creating+and+authenticating+users http://xxx-xxx.rhcloud.com/explorer/#!/Users New User 2.1. Click POST /Users 2.2. Click to set as parameter value 2.3. Change value: username ’tt’, email ’tt@tt.com’ . Add new “password”: “xxx”, 2.4. Try it out! if Response Code = 200 then success. Login User 3.1. before login, try to Click Get /Users/{id} , put id = 1, Try it out! get error msg: 401 Authorization Required….. now can sure, not login. 3.2. Click POST /Users/login 3.3. credentials value input {“username”:“tt”, “password”:“xxx”} 3.4. if see id , ttl, created, userid then success. id = access token 3.5. copy id value, put access token on page top. click Set Access Token. 3.6. now go back 3.1, try again. now success. login user only can use by self fun. ...

2014-09-15 · 1 min · 130 words · Me

StrongLoop OpenShift offine-sync TEST

https://developers.openshift.com/en/getting-started-client-tools.html#ubuntu http://docs.strongloop.com/display/SL/OpenShift 3.http://xxxx-xxxxx.rhcloud.com/ http://xxxx-xxxxx.rhcloud.com/explorer/ http://strongloop.com/strongblog/node-js-rest-api-openshift-redhat/?utm_source=tuicool old : loopback :http://loopback.io/ new : http://strongloop.com/ rhc create-app sl https://raw.github.com/strongloop/openshift-cartridge-strongloop/master/metadata/manifest.yml rhc show-app xxxxx 查相關資訊 rhc show-app xxxxx –gears quota 查空間 update to openshift, need to install local npm and strongloop *ubuntu * curl -sL https://deb.nodesource.com/setup | sudo bash - sudo apt-get install nodejs https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager npm install -g strongloop =========== ALL in LOCAL: slc loopback:datasource myMongoDB this is local, not on openshift if local no file, use rhc git-clone to get file in local. *ps.1 ...

2014-09-15 · 1 min · 156 words · Me