def pin_change_do(Req): if not Req.user.is_authenticated(): return denied(Req) Form = PinChangeForm(Req.POST, user=Req.user) Dict = {} if Form.is_valid(): pin_name = settings.ROOT_PATH + "pins_images/pin_%i.png" % ( Req.user.id) (Letters, Value) = pin(pin_name) i = None try: i = PinsImages.objects.get(user=Req.user) except PinsImages.DoesNotExist: i = PinsImages(user=Req.user, img=pin_name) i.req_vocabulary = Letters i.hash_value = generate_key_from(Value, settings.PIN_SALT) i.operator = Req.user i.status = "created" i.save() ##устанавливаем холд на вывод Key = start_show_pin(Req.user.id, 160000) return redirect("/pin_image_page/%s" % (Key)) else: t = loader.get_template("simple_form.html") Dict = {} Dict["form"] = Form.as_p() Dict["action"] = "/profile/pin_change_do" Dict["action_title"] = settings.pin_change_title Dict["pin_load"] = True return http_tmpl_context(Req, t, Dict)
def pin_change_do(Req): if not Req.user.is_authenticated(): return denied(Req) Form = PinChangeForm(Req.POST, user = Req.user) Dict = {} if Form.is_valid(): pin_name = settings.ROOT_PATH + "pins_images/pin_%i.png" % (Req.user.id) (Letters, Value) = pin(pin_name) i = None try: i = PinsImages.objects.get(user = Req.user) except PinsImages.DoesNotExist: i = PinsImages(user = Req.user, img = pin_name ) i.req_vocabulary = Letters i.hash_value = generate_key_from(Value, settings.PIN_SALT) i.operator = Req.user i.status = "processed" i.save() ##устанавливаем холд на вывод Key = start_show_pin(Req.user.id, 160000) return redirect( "/pin_image_page/%s" % (Key) ) else : t = loader.get_template("simple_form.html") Dict = {} Dict["form"] = Form.as_p() Dict["action"] = "/profile/pin_change_do" Dict["action_title"] = settings.pin_change_title Dict["pin_load"] = True return http_tmpl_context(Req, t, Dict)
def handle(self, *args, **options): for one_user in User.objects.all(): if not one_user.is_staff and one_user.is_active: Key1 = generate_key() Key2 = generate_key() PrivateKey = generate_key_from(Key1, one_user.email) new_obj = ApiKeys(public_key = Key2, private_key = PrivateKey, user = one_user) new_obj.save()
def clean(self): CheckPin = None try: CheckPin = self.fields["pin"].value except: raise forms.ValidationError(_(u"Вы неправильно ввели PIN-код ")) Pin = None try: Pin = PinsImages.objects.get(user=self.__user) except PinsImages.DoesNotExist: raise forms.ValidationError(_(u"Обратитесь в службу поддержки, что бы получить pin-код для вывода ")) if Pin.hash_value != generate_key_from(CheckPin, settings.PIN_SALT): raise forms.ValidationError(_(u"Вы неправильно ввели PIN-код ")) return self.cleaned_data
def clean(self): CheckPin = None try: CheckPin = self.fields["pin"].value except : raise forms.ValidationError(_(u"Вы неправильно ввели PIN-код ")) Pin = None try: Pin = PinsImages.objects.get( user = self.__user ) except PinsImages.DoesNotExist: raise forms.ValidationError(_(u"Обратитесь в службу поддержки, что бы получить pin-код для вывода ")) if Pin.hash_value != generate_key_from(CheckPin, settings.PIN_SALT): raise forms.ValidationError(_(u"Вы неправильно ввели PIN-код ")) return self.cleaned_data
def new_api_key(one_user): Key1 = generate_key() Key2 = generate_key() PrivateKey = generate_key_from(Key1, one_user.email) new_obj = ApiKeys(public_key=Key2, private_key=PrivateKey, user=one_user) new_obj.save()