diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 69e4d43..da23ae5 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,38 +1,50 @@ require 'digest' class UserController < ApplicationController - @@secret_key + def auth - # Defining secret key dependent on hostname - @@secret_key = request.host == 'beathaven.org' ? 'sdgwSbl3nNE4ZxafuPrp' : 's5zyjb693z6uV4rbhEyc' @res = {} + check = check_auth(params) - unless params[:expire].nil? or params[:mid].nil? or params[:secret].nil? or params[:sid].nil? or params[:sig].nil? - # Calculating hash - hash = 'expire='+ params[:expire] +'mid='+ params[:mid] +'secret='+ params[:secret] +'sid='+ params[:sid] + @@secret_key - hash_md5 = Digest::MD5.hexdigest(hash) - - if Digest::MD5.hexdigest(hash) == params[:sig] - @res[:status] = 'hello' - user = User.find_by_vkid(params[:mid]) - if user.nil? - user = User.new - user.vkid = params[:mid] - user.save - end - if user.name.nil? and not params[:name].nil? - user.name = params[:name] - user.save - end - @res[:id] = user.id - @res[:username] = user.name - else - @res[:status] = 'bad signature' + if check == true + @res[:status] = 'hello' + user = User.find_by_vkid(params[:mid]) + if user.nil? + user = User.new + user.vkid = params[:mid] + user.save end + @res[:id] = user.id + @res[:username] = user.name + elsif check == false + @res[:status] = 'bad signature' else @res[:status] = 'bad params' end render :json => @res end + + def update + + end + + private + + def check_auth params + secret_key = request.host == 'beathaven.org' ? 'sdgwSbl3nNE4ZxafuPrp' : 's5zyjb693z6uV4rbhEyc' + unless params[:expire].nil? or params[:mid].nil? or params[:secret].nil? or params[:sid].nil? or params[:sig].nil? + # Calculating hash + hash = 'expire='+ params[:expire] +'mid='+ params[:mid] +'secret='+ params[:secret] +'sid='+ params[:sid] + secret_key + hash_md5 = Digest::MD5.hexdigest(hash) + if Digest::MD5.hexdigest(hash) == params[:sig] + return true + else + return false + end + else + return 'bad params' + end + end + end diff --git a/public/images/icns/settings.png b/public/images/icns/settings.png new file mode 100644 index 0000000..cd2864f Binary files /dev/null and b/public/images/icns/settings.png differ diff --git a/public/index.html b/public/index.html index ea19d85..43dc1b6 100644 --- a/public/index.html +++ b/public/index.html @@ -15,6 +15,7 @@ + @@ -49,7 +50,10 @@