Created
July 30, 2014 20:29
-
-
Save elijahc/db4c35fcf75b65a3c006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blink < Sinatra::Base | |
require 'rbc' | |
get '/user/:id' do |id| | |
@user = User.find(id) | |
haml :users_show | |
end | |
get '/user/:id/destroy' do |id, status| | |
restrict! :to_below => 3 | |
user = User.find(id) | |
user.destroy | |
flash[:info] = "User Deleted" | |
redirect '/users/manage' | |
end | |
get '/bsiaccount/:id/test' do |id| | |
restrict! :to_below => 6 | |
@account = BsiAccount.find(id) | |
if @account | |
key = { | |
:user => @account.username, | |
:pass => @account.password, | |
:url => 'https://websvc-mirror.bsisystems.com:2271/bsi/xmlrpc', | |
:server => 'PCF' | |
} | |
bsi = RBC.new(@account.gen_mirror_key) | |
session = bsi.common.logon | |
if session | |
flash[:success] = "Able to login to BSI" | |
@account.working=true | |
@account.save | |
bsi.common.logoff | |
else | |
flash[:warning] = "Unable to login to BSI, password may be incorrect" | |
@account.working=false | |
@account.save | |
end | |
else | |
flash[:danger] = "Unable to find this BSI account" | |
end | |
redirect "/user/#{@current_user.id}" | |
end | |
get '/bsiaccount/:id/delete' do |id| | |
restrict! :to_below => 6 | |
@account = BsiAccount.find(id) | |
if @account | |
@account.destroy | |
flash[:success] = "Account destroyed" | |
else | |
flash[:danger] = "Error unable to find account" | |
end | |
redirect "/user/#{@current_user.id}" | |
end | |
post '/user/:id/bsiaccounts' do |id| | |
restrict! :to_below => 6 | |
@user = User.find(id) | |
bsiaccount = BsiAccount.find_or_create(username: params['username'], user: @user) | |
if bsiaccount | |
bsiaccount.password=params['password'] | |
bsiaccount.save | |
flash[:success] = "Account linked" | |
else | |
flash[:danger] = "Error occurred linking account" | |
end | |
redirect back | |
end | |
post '/user/:id/pin' do |id| | |
restrict! :to_below => 3 | |
user = User.find(id) | |
user.pin=params['PIN'] | |
user.save | |
flash[:success]= "Successfully updated PIN" | |
redirect "/user/#{id}" | |
end | |
get '/user/:id/:attr/:val' do |id, attr, val| | |
restrict! :to_below => 3 | |
user = User.find(id) | |
old_value = user.send(attr) | |
user.send("#{attr}=", val) | |
user.save | |
flash[:success]= "Successfully changed #{user.name}'s #{attr} from #{old_value} to #{val}" | |
redirect '/users/manage' | |
end | |
get '/users/manage' do | |
restrict! :to_below => 3 | |
@pending_users = User.where(status: 'pending') | |
@revoked_users = User.where(status: 'revoked') | |
@users = User.where(status: 'active') | |
haml :users_manage | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment