def setup_g2a_verify(request, val): CachedKey = 'qr_' + str(request.user.id) cache = caching() Secret = cache.get(CachedKey, False) if not Secret: return json_false500(request) if g2f.auth(Secret, val): Setting = None SettingType = CustomSettings.objects.get(title = "g2a") try : Setting = UserCustomSettings.objects.get(user = request.user, setting = SettingType ) except UserCustomSettings.DoesNotExist: Setting = UserCustomSettings(user = request.user, setting = SettingType, value = SettingType.def_value ) valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % (request.user.id) os.remove(valid_image) Setting.value = Secret Setting.save() request.session['use_f2a'] = True return json_true(request) else : return json_false500(request)
def g2a_turn_off(request): print request.session['use_f2a'] setting = UserCustomSettings.objects.get(user = request.user, setting__title="g2a" ) setting.value = "no" setting.save() request.session['use_f2a'] = False return json_true(request)
def time(Req): Dict = {"use_f2a": False} cache = caching() if Req.user.is_authenticated(): Dict["logged"] = True if Req.session.has_key("deal_comission"): Dict["deal_comission"] = Req.session["deal_comission_show"] else: ComisObj = UserCustomSettings.objects.get(user_id=Req.user.id, setting__title="deal_comission") DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100")) Req.session["deal_comission_show"] = DealComission Req.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value)) Dict["deal_comission"] = DealComission if Req.session.has_key("use_f2a"): Dict["use_f2a"] = Req.session["use_f2a"] else: Dict["use_f2a"] = False else: Dict["deal_comission"] = "0.10" if Req.session.session_key is not None: cache.set("chat_" + Req.session.session_key, Req.user.username, 60000) Dict["usd_uah_rate"] = get_memory_var("usd_uah_rate") Dict["time"] = datetime.now().strftime("%d.%m.%y %H:%M:%S") Dict["sessionid"] = Req.session.session_key return json_true(Req, Dict)
def setup_g2a(request): CachedKey = 'qr_' + str(request.user.id) cache = caching() Dict = {} (base32, base16) = g2f.newSecret() Link = g2f.getQRLink(request.user.username, base32) imgRequest = urllib2.Request(Link) imgData = urllib2.urlopen(imgRequest).read() valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % (request.user.id) F = open(valid_image,'wb') F.write(imgData) F.close() Dict["g2a_private_key32"] = base32 Dict["g2a_private_key"]= base16 temp_qr = generate_key("qr") Dict["g2a_qr"] = "/profile/qr?key=%s" % ( temp_qr ) cache.set("temp_qr" + temp_qr, request.user.id, 300) cache.set(CachedKey, base32,600) return json_true(request, Dict)
def hide(Req, Id): if not Req.user.is_authenticated(): return json_denied(Req) else: MyMsg = main.models.Msg.objects.get(id = int(Id) ) if MyMsg.user_from == Req.user: MyMsg.user_hide_from = "true" MyMsg.save() return json_true(Req) if MyMsg.user_to == Req.user: MyMsg.user_hide_to = "true" MyMsg.save() return json_true(Req) return json_denied(Req)
def hide(Req, Id): if not Req.user.is_authenticated(): return json_denied(Req) else: MyMsg = main.models.Msg.objects.get(id=int(Id)) if MyMsg.user_from == Req.user: MyMsg.user_hide_from = "true" MyMsg.save() return json_true(Req) if MyMsg.user_to == Req.user: MyMsg.user_hide_to = "true" MyMsg.save() return json_true(Req) return json_denied(Req)
def call_back_url(Req, OrderId): # ok_invoice # ok_txn_status rlog_req = OutRequest(raw_text=str(Req.REQUEST), from_ip=get_client_ip(Req)) Body = "ok_verify=true&{0}".format(Req.body) Url = "https://www.okpay.com/ipn-verify.html" headers = {"User-Agent": "Mozilla 5.10", "Content-Type": "text/xml"} request = urllib2.Request(Url, Body, headers) response = urllib2.urlopen(request) d = response.read() rlog_req.raw_text = rlog_req.raw_text + " response '{0}' ".format(d) import logging logging.error("okpay" + d) if d != u"VERIFIED": # and d!= u"TEST": rlog_req.save() return json_false(Req) rlog_req.save() FactAmnt = Decimal(Req.REQUEST["ok_txn_net"]) if Req.REQUEST[u"ok_txn_status"] == u"completed": if process_in(Req.REQUEST["ok_invoice"], FactAmnt, Decimal("0.0"), settings.COMMON_SALT): return json_true(Req) else: return json_false(Req) return json_false(Req)
def time(Req): Dict = {"use_f2a": False} cache = caching() if Req.user.is_authenticated(): Dict["logged"] = True if Req.session.has_key("deal_comission"): Dict["deal_comission"] = Req.session["deal_comission_show"] else: ComisObj = UserCustomSettings.objects.get(user_id=Req.user.id, setting__title="deal_comission") DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100")) Req.session["deal_comission_show"] = DealComission Req.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value)) Dict["deal_comission"] = DealComission if Req.session.has_key("use_f2a"): Dict["use_f2a"] = Req.session["use_f2a"] else: Dict["use_f2a"] = False else: Dict["deal_comission"] = "0.10" if Req.session.session_key is not None: cache.set("chat_" + Req.session.session_key, Req.user.username, 60000) Dict["usd_uah_rate"] = get_memory_var("usd_uah_rate") Dict["time"] = (datetime.now() - datetime(1970,1,1)).total_seconds() # datetime.now().strftime("%d.%m.%y %H:%M:%S") Dict["sessionid"] = Req.session.session_key return json_true(Req, Dict)
def setup_g2a(request): CachedKey = 'qr_' + str(request.user.id) cache = caching() Dict = {} (base32, base16) = g2f.newSecret() Link = g2f.getQRLink(request.user.username, base32) imgRequest = urllib2.Request(Link) imgData = urllib2.urlopen(imgRequest).read() valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % ( request.user.id) F = open(valid_image, 'wb') F.write(imgData) F.close() Dict["g2a_private_key32"] = base32 Dict["g2a_private_key"] = base16 temp_qr = generate_key("qr") Dict["g2a_qr"] = "/profile/qr?key=%s" % (temp_qr) cache.set("temp_qr" + temp_qr, request.user.id, 300) cache.set(CachedKey, base32, 600) return json_true(request, Dict)
def setup_g2a_verify(request, val): CachedKey = 'qr_' + str(request.user.id) cache = caching() Secret = cache.get(CachedKey, False) if not Secret: return json_false500(request) if g2f.auth(Secret, val): Setting = None SettingType = CustomSettings.objects.get(title="g2a") try: Setting = UserCustomSettings.objects.get(user=request.user, setting=SettingType) except UserCustomSettings.DoesNotExist: Setting = UserCustomSettings(user=request.user, setting=SettingType, value=SettingType.def_value) valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % ( request.user.id) os.remove(valid_image) Setting.value = Secret Setting.save() request.session['use_f2a'] = True return json_true(request) else: return json_false500(request)
def call_back_url(Req, OrderId): # ok_invoice # ok_txn_status rlog_req = OutRequest(raw_text=str(Req.REQUEST), from_ip=get_client_ip(Req)) Body = "ok_verify=true&{0}".format(Req.body) Url = "https://www.okpay.com/ipn-verify.html" headers = {'User-Agent': 'Mozilla 5.10', 'Content-Type': 'text/xml'} request = urllib2.Request(Url, Body, headers) response = urllib2.urlopen(request) d = response.read() rlog_req.raw_text = rlog_req.raw_text + " response '{0}' ".format(d) import logging logging.error("okpay" + d) if d != u"VERIFIED": #and d!= u"TEST": rlog_req.save() return json_false(Req) rlog_req.save() FactAmnt = Decimal(Req.REQUEST["ok_txn_net"]) if Req.REQUEST[u"ok_txn_status"] == u"completed": if process_in(Req.REQUEST["ok_invoice"], FactAmnt, Decimal("0.0"), settings.COMMON_SALT): return json_true(Req) else: return json_false(Req) return json_false(Req)
def auth(Req): Nonce = Req.REQUEST.get("nonce", None) if Nonce is None: return json_false500(Req) (Sign, PublicKey) = (None, None) Sign = Req.META.get('HTTP_API_SIGN', None) if Sign is None: return json_false500(Req, { "description": "invalid_params", "key": "api_sign" }) PublicKey = Req.META.get('HTTP_PUBLIC_KEY', None) if PublicKey is None: return json_false500(Req, { "description": "invalid_params", "key": "public_key" }) try: Req.user = check_api_sign(PublicKey, Sign, Req.body) Cache = caching() Cache.set("nonce_" + PublicKey, int(Nonce), 50000) Nonce = Cache.get("nonce_" + PublicKey) return json_true(Req, {"nonce": Nonce, "public_key": PublicKey}) except: return json_false500(Req, {"description": "auth_faild"})
def g2a_turn_off(request): print request.session['use_f2a'] setting = UserCustomSettings.objects.get(user=request.user, setting__title="g2a") setting.value = "no" setting.save() request.session['use_f2a'] = False return json_true(request)
def user_settings(Req, Name, Value): if not Req.user.is_authenticated(): return json_denied(Req, {"ru_description": u"Для изменения персональных настроек пожайлуста авторизируйтесь"}) if Value == "yes": Value = "yes" else: Value = "no" Setting = None try : Setting = CustomSettings.objects.get(title = Name) Object = UserCustomSettings.objects.get(user = Req.user, setting = Setting ) Object.value = Value Object.save() return json_true(Req) except UserCustomSettings.DoesNotExist: obj = UserCustomSettings(user = Req.user, setting = Setting, value = Value ) obj.save() return json_true(Req)
def user_settings(Req, Name, Value): if not Req.user.is_authenticated(): return json_denied( Req, { "ru_description": u"Для изменения персональных настроек пожайлуста авторизируйтесь" }) if Value == "yes": Value = "yes" else: Value = "no" Setting = None try: Setting = CustomSettings.objects.get(title=Name) Object = UserCustomSettings.objects.get(user=Req.user, setting=Setting) Object.value = Value Object.save() return json_true(Req) except UserCustomSettings.DoesNotExist: obj = UserCustomSettings(user=Req.user, setting=Setting, value=Value) obj.save() return json_true(Req)
def call_back_url(Req): # ok_invoice # ok_txn_status rlog_req = OutRequest(raw_text=str(Req.REQUEST), from_ip=get_client_ip(Req)) rlog_req.save() FactAmnt = Decimal(Req.REQUEST["amount"]) body = Req.body sha1_hash = Req.REQUEST['sha1_hash'] if sha1_hash != signature(Req.REQUEST, sdk.ya_settings.SECRET): return json_false(Req) if process_in(Req.REQUEST["label"], FactAmnt, Decimal("0.0"), settings.COMMON_SALT): return json_true(Req) else: return json_false(Req)
def reset(Req): if not Req.user.is_authenticated(): return denied(Req) hold = HoldsWithdraw(user=Req.user, hours=settings.default_hold) hold.save() NewPwd = generate_key("hold")[10:30] # if settings.DEBUG is False: Email = Req.user.email send_mail(u'Обновление пароля на сайте ' + settings.BASE_HOST, reset_pwd_mail(Req.user, NewPwd), [Email], fail_silently=False) Req.user.set_password(NewPwd) Req.user.save() return json_true(Req)
def reset(Req): if not Req.user.is_authenticated(): return denied(Req) hold = HoldsWithdraw(user = Req.user, hours = settings.default_hold) hold.save() NewPwd = generate_key("hold")[10:30] #if settings.DEBUG is False: Email = Req.user.email send_mail(u'Обновление пароля на сайте ' + settings.BASE_HOST, reset_pwd_mail(Req.user, NewPwd), settings.EMAIL_HOST_USER, [ Email ], fail_silently = False) Req.user.set_password(NewPwd) Req.user.save() return json_true(Req)
def create(Req): if not Req.user.is_authenticated(): return denied(Req) else: Username = Req.REQUEST.get('whom', None) Msg = Req.REQUEST.get('msg', None) if Msg is None : return http_json(Req, {'status':False, "description":ugettext("Fill fields correctly")}) if Username is None : return http_json(Req, {'status':False, "description":ugettext("Fill fields correctly")}) if Username == Req.user.username: return http_json(Req, {'status':False, "description":ugettext("Sender and reciver the same user")}) try : To = User.objects.get(username = Username) msg(Msg, Req.user, To) except User.DoesNotExist: return http_json(Req, {'status':False,"description":ugettext("We can't find reciver of the message")}) return json_true(Req)
def auth(Req): Nonce = Req.REQUEST.get("nonce", None) if Nonce is None : return json_false500(Req) (Sign, PublicKey) = (None, None) Sign = Req.META.get('HTTP_API_SIGN', None) if Sign is None: return json_false500(Req, {"description":"invalid_params", "key": "api_sign"} ) PublicKey = Req.META.get('HTTP_PUBLIC_KEY', None) if PublicKey is None: return json_false500(Req, {"description":"invalid_params","key": "public_key"} ) try : Req.user = check_api_sign(PublicKey, Sign, Req.body ) Cache = caching() Cache.set("nonce_" + PublicKey, int(Nonce), 50000) Nonce = Cache.get("nonce_" + PublicKey) return json_true(Req, {"nonce": Nonce,"public_key": PublicKey}) except: return json_false500(Req,{"description":"auth_faild"})
def create(Req): if not Req.user.is_authenticated(): return denied(Req) else: if cache.get("cryptonbanned_" + Req.user.username, False): return denied(Req) Username = Req.REQUEST.get('whom', None) Msg = Req.REQUEST.get('msg', None) if Msg is None: return http_json(Req, {'status': False, "description": ugettext("Fill fields correctly")}) if Username is None: return http_json(Req, {'status': False, "description": ugettext("Fill fields correctly")}) if Username == Req.user.username: return http_json(Req, {'status': False, "description": ugettext("Sender and reciver the same user")}) try: To = User.objects.get(username=Username) msg(Msg, Req.user, To) except User.DoesNotExist: return http_json(Req, {'status': False, "description": ugettext("We can't find reciver of the message")}) return json_true(Req)
def suspend(req): uwsgi.signal(96) return json_true(req, {})
def reload(req): uwsgi.signal(98) return json_true(req, {})
def stop(req): uwsgi.signal(99) return json_true(req, {})
def start(req): uwsgi.signal(97) return json_true(req, {})