Esempio n. 1
0
def postSave_User(sender, instance, created, **kwargs):
    if created == True and not instance.is_staff:
        token = account_activation_token.make_token(instance)
        uidb64 = urlsafe_base64_encode(bytes(str(instance.pk), 'utf-8'))

        # Send email
        subject = 'Activación de Cuenta | Buratovich Hnos.'
        from_email = '*****@*****.**'

        data = {
            'company_name': instance.userinfo.company_name,
            'username': instance.username,
            'password': instance._pswd,
            'uidb64': uidb64,
            'token': token
        }
        message = render_to_string('email_new_user.html', {'data': data})

        try:
            mail = EmailMessage(subject,
                                message,
                                to=[instance.email],
                                from_email=from_email)
            mail.content_subtype = 'html'
            mail.send()
        except BadHeaderError:
            print('Invalid header found.')
        except smtplib.SMTPException:
            print('Error: Unable to send email')
Esempio n. 2
0
def register(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        form2=UserProfileForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            message = render_to_string('acc_active_email.html', {
                'user':user, 'domain':current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            # Sending activation link in terminal
            # user.email_user(subject, message)
            mail_subject = 'Activate your account.'
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse('Please confirm your email address to complete the registration.')
            # return render(request, 'acc_active_sent.html')
    else:
        form = SignupForm()
        form2=UserProfileForm()
    return render(request, 'signup.html', {'form': form,'form2': form2})
Esempio n. 3
0
def become_mentor(request):
    if request.method == 'POST':
        first_name = str(request.POST.get('firstname'))
        last_name = str(request.POST.get('lastname'))
        email = str(request.POST.get('email'))
        phone_number = int(request.POST.get('phone'))
        twitter = str(request.POST.get('twitter'))
        github = str(request.POST.get('gitlink'))
        linkdin = str(request.POST.get('linkedin'))
        mentorship_field = str(request.POST.get('sfield'))
        medium = str(request.POST.get('burl'))
        avatar = request.FILES.get('image')
        facebook = str(request.POST.get('fblink'))
        short_bio = str(request.POST.get('bio'))

        if check_email_exists(email):
            messages.warning(
                request, 'Oops user with the email already exists.')
            return render(request, '../templates/become_mentor.html')

        else:
            mentor = MentorUser(email=email)
            mentor.save()
            profile = MentorProfile(user=mentor, phone_number=phone_number,
                              twitter=twitter, github=github, linkdin=linkdin,
                              mentorship_field=mentorship_field, medium=medium,
                              first_name=first_name, last_name=last_name,
                              avatar=avatar,facebook=facebook, short_bio=short_bio)
            profile.save()
            messages.success(
                request, 'Registration successful. \
                Account activation email sent.')

            subject = 'Activate Your Mentorbot Account'
            domain = config('DOMAIN')
            uid = urlsafe_base64_encode(force_bytes(mentor.pk)).decode()
            token = account_activation_token.make_token(mentor)
            activation_link = reverse('activate', args=[uid, token])
            activation_url = "{}{}".format(domain, activation_link)
            message = render_to_string('account_activation_email.html', {
                'mentor': mentor,
                'activation_url': activation_url
            })
            mentor.email_user(subject, message)
            return redirect('account_activation_sent')
    return render(request, '../templates/become_mentor.html')
Esempio n. 4
0
def register(request):
    #registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.is_active = False
            user.save()

            profile = profile_form.save()
            profile.user = user
            profile.save()

            current_site = get_current_site(request)
            subject = 'activate your account'
            message = render_to_string(
                'registration/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('account_activation_sent')
        #   registered = True
        #  user_form = UserForm()
        # profile_form = UserProfileForm()
        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request, 'registration/registration_form.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Esempio n. 5
0
    def send_activate_mail(self, user, form):
        current_site = get_current_site(self.request)
        mail_subject = _('Activate your Soltoon account')
        context = {
            'user': user,
            'domain': current_site.domain,
            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
            'token': account_activation_token.make_token(user),
        }
        message = render_to_string('website/mail/signup_activate_mail.html',
                                   context)

        to_email = form.cleaned_data.get('email')
        email = EmailMessage(mail_subject, message, to=[to_email])
        email.send()

        messages.success(
            self.request,
            _('User has been created. check your email for confirmation mail.')
        )
Esempio n. 6
0
	def handle(self, *args, **options):

		def evalText(text):
			# Decode text in latin iso-8859-1 like (0xd1 --> ñ)
			return unicode(text.strip(' ').decode('iso-8859-1'))

		def evalTextEncode(text):
			texto = text.strip(' ').encode('iso-8859-1')
			return texto

		# Disconnect signals
		pre_save.disconnect(receiver= preSave_User, sender=User, dispatch_uid='website.signals.preSave_User')
		post_save.disconnect(receiver= postSave_User, sender=User, dispatch_uid='website.signals.postSave_User')

		txt = os.path.join(settings.BASE_DIR, 'cuentas.txt')

		new_accounts = open(os.path.join(settings.BASE_DIR, 'new_accounts.txt'), 'a')
		new_accounts.write('Codigo' + '\t' + 'Nombre' + '\t'+ 'Usuario' + '\t' + 'Email' + '\t' + 'Password' + '\t' + 'Token' + '\t' + 'UID' + '\n')

		with open(txt, 'r') as accounts:

			# Exclude header
			accounts.next()

			for line in accounts:
				# Delete new line character
				line = line.replace('\n', '').replace('\r', '')
				if len(line) > 0:
					data = re.split('\t', line)
					cod = data[0]
					name = evalText(data[1])
					user = evalText(data[2])
					# Get the first email account if there is more than one
					email = data[3].replace('"', '')
					email = re.split(';', email)
					email = evalText(email[0])
					try:
						# User
						passw = User.objects.make_random_password(8)
						#print cod, name, user, email, passw
						user = User.objects.create_user(user, email, passw)
						#print "user created"
						user.is_staff = False
						user.is_active = False
						user.save()
						#print "user saved"

						# UserInfo
						userinfo = UserInfo(user_id=user.id)
						userinfo.algoritmo_code = cod
						userinfo.company_name = name
						userinfo.account_confirmed = False
						userinfo.random_password = True
						userinfo.save()
						#print "userinfo created"

						# Token
						token = account_activation_token.make_token(user)
						uidb64 = urlsafe_base64_encode(str(user.pk))

						new_line = cod + '\t' + evalTextEncode(name) + '\t' + evalTextEncode(user.username) + '\t' + evalTextEncode(email) + '\t' + evalTextEncode(passw) + '\t' + evalTextEncode(token) + '\t' + evalTextEncode(uidb64) + '\n'
						new_accounts.write(new_line)

						self.stdout.write(self.style.SUCCESS('Successfully created user "%s"' % name))
					except IntegrityError:
						print 'Error', name

		new_accounts.close()
Esempio n. 7
0
def register_view(request):
    if request.method == "POST":

        username = request.POST['username']
        email = request.POST['email']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        birthdate = request.POST['date']
        createdat = datetime.datetime.now()
        faculty = request.POST['Bölüm']
        gender = request.POST['gender']
        converted = datetime.datetime.strptime(birthdate, '%Y-%m-%d')
        if str(email).split('@')[1] != 'isik.edu.tr':
            messages.error(
                request,
                'Güvenliğiniz için sadece Işık mailiniz ile kayıt olabilirsiniz.'
            )
            return redirect('register')
        if password1 != password2:
            messages.error(request, 'İki şifre eşleşmiyor.')
            return redirect('register')
        if len(password1) < 8:
            messages.error(request, 'Şifre 8 karakterden küçük olamaz.')
            return redirect('register')
        if converted.year > createdat.year:
            messages.error(request,
                           'Geçersiz doğum tarihi.Geçerli bir tarih giriniz.')
            return redirect('register')
        if email and User.objects.filter(email=email).exclude(
                username=username).exists():
            messages.error(
                request,
                'Email sistemde kayıtlı.Lütfen başka bir email giriniz.')
            return redirect('register')
        if User.objects.filter(username=username).exists():
            messages.error(
                request,
                'Kullanıcı adı sistemde kayıtlı.Lütfen başka bir kullanıcı adı giriniz.'
            )
            return redirect('register')

        user = User.objects.create_user(username=username,
                                        email=email,
                                        password=password1)
        profile = UserProfile(gender=gender,
                              faculty=faculty,
                              user=user,
                              birthdate=birthdate,
                              createdat=createdat)
        # user_test = UserProfile.objects.get(pk=13)
        profile.save()
        subject = 'Aramıza hoşgeldin - The Insider Sight'
        current_site = get_current_site(request)
        message = render_to_string(
            'account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
        user.email_user(subject, message)

        messages.success(request, 'Onay maili belirttiğiniz maile gönderildi.')
        return redirect('register')
    else:
        return render(request, 'register.html')