def register(request): """ Display form for registration **Context** registration form **Template:** :template:`register.html` """ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): try: salt = hashlib.sha1(str(random()).encode("utf-8")).hexdigest()[:5] activation_key = hashlib.sha1((salt + form.cleaned_data["email"]).encode("utf-8")).hexdigest() key_expires = datetime.datetime.now() + datetime.timedelta(2) email_subject = 'Embigo - Potwierdzenie Rejestracji ' email_body = "Witaj %s, dziękujemy za rejestrację w Embigo. By zakończyć proces rejestracji musisz, w przeciągu" \ " 48 godzin kliknąć w poniższy link:\nhttp://%s/confirm/%s" % ( form.cleaned_data["username"], request.META["HTTP_HOST"], activation_key) send_mail(email_subject, email_body, '*****@*****.**', [form.cleaned_data["email"]], fail_silently=False) new_user = form.save() new_user.is_active = False new_user.save() new_space_user = SpaceUser(uid=uuid1(), rights=embigo_default_rights(), space=embigo_main_space(), user=new_user) new_space_user.save() colors = ["#FEE6AA","#FDD777","#FCC845","#FBBA13","#FEAAAA","#FD7777","#FC4545","#FB1313","#EBAAFE","#E077FD","#D545FC","#C913FB","#B9AAFE","#9077FD","#6745FC","#3E13FB","#AAE0FE","#77CEFD","#45BCFC","#13AAFB","#AAFECA","#77FDAB","#45FC8B","#13FB6C"] color = random.sample(colors, 1)[0]; embigo_user = EmbigoUser(user=new_user, activation_key=activation_key, key_expires=key_expires, hash_type='ACTIVATE_HASH') embigo_user.save() return HttpResponseRedirect(request.GET.get("next", "/"), RequestContext(request)) except SMTPRecipientsRefused: form.add_error("email","Błąd podczas wysyłania maila. Upewnij się czy wprowadzony adres e-mail jest poprawny.") except Exception as e: new_user.delete() raise e else: form = RegistrationForm() context = {'form': form} return render(request, 'register.html', context)
def test_create_embigo_space(self): create_embigo_space() embigo = embigo_main_space() self.assertEqual(embigo.name, "embigo")