示例#1
0
def validate_email(request):
	"""
	POST only, validates email during registration
	"""
	email = request.POST.get('email')
	try:
		utils.check_email(email)
		response = VALIDATION_IS_OK
	except ValidationError as e:
		response = e.message
	return HttpResponse(response, content_type='text/plain')
示例#2
0
    def profile_save_user(self, in_message):
        message = in_message[VarNames.CONTENT]
        userprofile = UserProfile.objects.get(id=self.user_id)
        email_verification_id = userprofile.email_verification_id
        un = message[UserProfileVarNames.USERNAME]
        email = message[UserProfileVarNames.EMAIL]
        if userprofile.username != un:
            check_user(un)
        if userprofile.email != email:
            check_email(email)
            if userprofile.email and userprofile.email_verification and userprofile.email_verification.verified:
                verification = Verification(
                    type_enum=Verification.TypeChoices.email,
                    user_id=self.id,
                    email=email)
                verification.save()
                send_email_change(self.request, un, userprofile.email,
                                  verification, email)
                self.ws_write(
                    self.default(
                        "In order to change an email please confirm it from you current address. We send you an verification email to {}."
                        .format(userprofile.email), Actions.GROWL_MESSAGE,
                        HandlerNames.WS))
                email = userprofile.email  # Don't change email, we need to verify it!
            elif email:
                new_ver = send_new_email_ver(self.request, userprofile, email)
                email_verification_id = new_ver.id

        sex = message[UserProfileVarNames.SEX]
        UserProfile.objects.filter(id=self.user_id).update(
            username=un,
            name=message[UserProfileVarNames.NAME],
            city=message[UserProfileVarNames.CITY],
            surname=message[UserProfileVarNames.SURNAME],
            email=email,
            birthday=message[UserProfileVarNames.BIRTHDAY],
            contacts=message[UserProfileVarNames.CONTACTS],
            sex=settings.GENDERS_STR[sex],
            email_verification=email_verification_id)
        self.publish(
            self.set_user_profile(in_message[VarNames.JS_MESSAGE_ID], message),
            self.channel)
        if userprofile.sex_str != sex or userprofile.username != un:
            self.publish(self.changed_user_profile(sex, self.user_id, un),
                         settings.ALL_ROOM_ID)
示例#3
0
 def post(self, request):
     rp = request.POST
     logger.info('Got register request %s',
                 hide_fields(rp, ('password', 'repeatpassword')))
     (username, password, email) = (rp.get('username'), rp.get('password'),
                                    rp.get('email'))
     check_user(username)
     check_password(password)
     check_email(email)
     user_profile = UserProfile(username=username,
                                email=email,
                                sex_str=rp.get('sex'))
     user_profile.set_password(password)
     create_user_model(user_profile)
     # You must call authenticate before you can call login
     auth_user = authenticate(username=username, password=password)
     if email:
         send_sign_up_email(user_profile, request.get_host(), request)
     djangologin(request, auth_user)
     return HttpResponse(settings.VALIDATION_IS_OK,
                         content_type='text/plain')
示例#4
0
	def post(self, request):
		try:
			rp = request.POST
			logger.info('Got register request %s', hide_fields(rp, ('password', 'repeatpassword')))
			(username, password, email) = (rp.get('username'), rp.get('password'), rp.get('email'))
			check_user(username)
			check_password(password)
			check_email(email)
			user_profile = UserProfile(username=username, email=email, sex_str=rp.get('sex'))
			user_profile.set_password(password)
			create_user_model(user_profile)
			# You must call authenticate before you can call login
			auth_user = authenticate(username=username, password=password)
			message = VALIDATION_IS_OK  # redirect
			if email:
				send_email_verification(user_profile, request.get_host())
			djangologin(request, auth_user)
		except ValidationError as e:
			message = e.message
			logger.debug('Rejecting request because "%s"', message)
		return HttpResponse(message, content_type='text/plain')
示例#5
0
文件: views.py 项目: ruankranz/pychat
def validate_email(request):
    """
	POST only, validates email during registration
	"""
    utils.check_email(request.POST.get('email'))
    return HttpResponse(settings.VALIDATION_IS_OK, content_type='text/plain')