def oauth_ok(request): import requests if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] code = request.GET['code'] ok = settings.oauth_ok url = "https://api.odnoklassniki.ru/oauth/token.do?code="+code+"&client_id="+ok['id']+"&client_secret="+ok['key']+"&redirect_uri=http://"+settings.domain+"/oauth_ok&grant_type=authorization_code" aaa = requests.post(url) resp = json.loads(aaa.content) access_token = resp['access_token'] refresh_token = resp['refresh_token'] import hashlib sign=hashlib.md5('application_key='+ok['pub_key']+'method=users.getCurrentUser'+hashlib.md5(access_token+ok['key']).hexdigest() ).hexdigest() url = 'http://api.odnoklassniki.ru/token.do?method=users.getCurrentUser&access_token='+access_token+'&application_key='+ok['pub_key']+'&sig='+sign+'&format=json' url = 'http://api.odnoklassniki.ru/fb.do?method=users.getCurrentUser&access_token='+access_token+'&application_key='+ok['pub_key']+'&sig='+sign aaa = requests.get(url) res = json.loads(aaa.content) s = session(request) if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] user_id = str(res['uid']) user_id = 'user:ok:'+user_id user = request.db.doc.find_one({'_id':user_id }) if user and 'ban' in user['doc'] and user['doc']['ban'] == 'true': session_add_mess(u'Ошибка входа на сайт') redirect('/') return '' s['user_id'] = user_id[5:] s.save() name = res['first_name']+' '+res['last_name'] old = res['age'] if 'age' in res else '' is_mail = False if 'mail' in user['doc'] and user['doc']['mail']: is_mail = True if not user: is_mail = False user = {'_id': user_id, "alien":"vk", 'name': name, 'password': "******", "type": "table_row", "doc_type":"des:users", "doc":{"user":user_id, "old":old, "phone":"", "address":"", "mail":"", 'rate':0, 'date': create_date(), "home": "false", 'name': {'ru':name} }, "hierarchy": { "tree:des:users": "_" }} request.db.doc.save(user) request.db.doc.update({'_id':'role:simple_users'}, {'$set':{'users.'+user_id:'true'}} ) user = request.db.doc.find_one({'_id':user_id }) user['doc']['name'] = {cur_lang(): name} from libs.files.files import link_upload_post_ link_upload_post_( res['pic_2'], 'des:users', user_id, True) request.db.doc.save(user) session_add_mess('Вы успешно вошли на сайт') if is_mail: redirect('/') else: redirect('/add_email')
def oauth_vk(request): import requests s = session(request) if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] code = request.GET['code'] vk = settings.oauth_vk site = 'http://vk.com/' url = "https://api.vk.com/oauth/access_token?client_id="+ vk['id']+"&client_secret="+ vk['key']+"&code=" + code + "&redirect_uri=http://"+settings.domain+"/oauth_vk" aaa = requests.get(url) resp = json.loads(aaa.content) access_token = resp['access_token'] user_id = resp['user_id'] url = 'https://api.vk.com/method/getProfiles?uid='+str(user_id)+'&access_token='+access_token+'&fields=screen_name,email,useroffline,photo' aaa = requests.get(url) res = json.loads(aaa.content)['response'][0] user_data = { 'id': 'vk:'+str(res['uid']), "link":'http://vk.com/'+res['screen_name'] } if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] user_id = str(user_id) user_id = 'user:vk:'+user_id user = request.db.doc.find_one({'_id':user_id }) if user and 'ban' in user['doc'] and user['doc']['ban'] == 'true': session_add_mess(u'Ошибка входа на сайт') redirect('/') return '' s['user_id'] = user_id[5:] s.save() name = res['first_name']+' '+res['last_name'] if not user: user = {'_id': user_id, "alien":"vk", 'name': name, 'password': "******", "type": "table_row", "doc_type":"des:users", "doc":{"user":user_id, "old": "", "phone":"", "address":"", "mail":"", 'rate':0, 'date': create_date(), "home": "false", 'name': {'ru':name} } } request.db.doc.save(user) request.db.doc.update({'_id':'role:simple_users'}, {'$set':{'users.'+user_id:'true'}} ) user = request.db.doc.find_one({'_id':user_id }) user['doc']['name'] = {cur_lang(): name} from libs.files.files import link_upload_post_ link_upload_post_( res['photo'], 'des:users', user_id, True) request.db.doc.save(user) session_add_mess(u'Вы успешно вошли на сайт') redirect('/')
def oauth_vk(request): import requests s = session(request) if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] code = request.GET['code'] vk = settings.oauth_vk site = 'http://vk.com/' url = "https://api.vk.com/oauth/access_token?client_id=" + vk[ 'id'] + "&client_secret=" + vk[ 'key'] + "&code=" + code + "&redirect_uri=http://" + settings.domain + "/oauth_vk" aaa = requests.get(url) resp = json.loads(aaa.content) access_token = resp['access_token'] user_id = resp['user_id'] url = 'https://api.vk.com/method/getProfiles?uid=' + str( user_id ) + '&access_token=' + access_token + '&fields=screen_name,email,useroffline,photo' aaa = requests.get(url) res = json.loads(aaa.content)['response'][0] user_data = { 'id': 'vk:' + str(res['uid']), "link": 'http://vk.com/' + res['screen_name'] } if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] user_id = str(user_id) user_id = 'user:vk:' + user_id user = request.db.doc.find_one({'_id': user_id}) if user and 'ban' in user['doc'] and user['doc']['ban'] == 'true': session_add_mess(u'Ошибка входа на сайт') redirect('/') return '' s['user_id'] = user_id[5:] s.save() name = res['first_name'] + ' ' + res['last_name'] if not user: user = { '_id': user_id, "alien": "vk", 'name': name, 'password': "******", "type": "table_row", "doc_type": "des:users", "doc": { "user": user_id, "old": "", "phone": "", "address": "", "mail": "", 'rate': 0, 'date': create_date(), "home": "false", 'name': { 'ru': name } } } request.db.doc.save(user) request.db.doc.update({'_id': 'role:simple_users'}, {'$set': { 'users.' + user_id: 'true' }}) user = request.db.doc.find_one({'_id': user_id}) user['doc']['name'] = {cur_lang(): name} from libs.files.files import link_upload_post_ link_upload_post_(res['photo'], 'des:users', user_id, True) request.db.doc.save(user) session_add_mess(u'Вы успешно вошли на сайт') redirect('/')
def oauth_ok(request): import requests if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] code = request.GET['code'] ok = settings.oauth_ok url = "https://api.odnoklassniki.ru/oauth/token.do?code=" + code + "&client_id=" + ok[ 'id'] + "&client_secret=" + ok[ 'key'] + "&redirect_uri=http://" + settings.domain + "/oauth_ok&grant_type=authorization_code" aaa = requests.post(url) resp = json.loads(aaa.content) access_token = resp['access_token'] refresh_token = resp['refresh_token'] import hashlib sign = hashlib.md5('application_key=' + ok['pub_key'] + 'method=users.getCurrentUser' + hashlib.md5(access_token + ok['key']).hexdigest()).hexdigest() url = 'http://api.odnoklassniki.ru/token.do?method=users.getCurrentUser&access_token=' + access_token + '&application_key=' + ok[ 'pub_key'] + '&sig=' + sign + '&format=json' url = 'http://api.odnoklassniki.ru/fb.do?method=users.getCurrentUser&access_token=' + access_token + '&application_key=' + ok[ 'pub_key'] + '&sig=' + sign aaa = requests.get(url) res = json.loads(aaa.content) s = session(request) if 'error' in request.GET: return 'ошибка авторизации' + request.GET['error_description'] user_id = str(res['uid']) user_id = 'user:ok:' + user_id user = request.db.doc.find_one({'_id': user_id}) if user and 'ban' in user['doc'] and user['doc']['ban'] == 'true': session_add_mess(u'Ошибка входа на сайт') redirect('/') return '' s['user_id'] = user_id[5:] s.save() name = res['first_name'] + ' ' + res['last_name'] old = res['age'] if 'age' in res else '' is_mail = False if 'mail' in user['doc'] and user['doc']['mail']: is_mail = True if not user: is_mail = False user = { '_id': user_id, "alien": "vk", 'name': name, 'password': "******", "type": "table_row", "doc_type": "des:users", "doc": { "user": user_id, "old": old, "phone": "", "address": "", "mail": "", 'rate': 0, 'date': create_date(), "home": "false", 'name': { 'ru': name } }, "hierarchy": { "tree:des:users": "_" } } request.db.doc.save(user) request.db.doc.update({'_id': 'role:simple_users'}, {'$set': { 'users.' + user_id: 'true' }}) user = request.db.doc.find_one({'_id': user_id}) user['doc']['name'] = {cur_lang(): name} from libs.files.files import link_upload_post_ link_upload_post_(res['pic_2'], 'des:users', user_id, True) request.db.doc.save(user) session_add_mess('Вы успешно вошли на сайт') if is_mail: redirect('/') else: redirect('/add_email')