Esempio n. 1
0
def validateSignup(**raw):
  """Validates the signup form input

  Validates the input from the signup form using the regex defined in settings

  Args:
    **raw: Collects all the named arguments

  Returns:
    A tuple containing:
      - Boolean: Whether there was an error or not
      - dict(): Containing the original params and the generated error params
  """
  error = False
  params = { 'username': raw['username'], 'email': raw['email'] }
  
  if not utils.validateUsername(raw['username']):
    params['error_username'] = settings.RE_USERNAME_FAIL
    error = True
  
  if not utils.validatePassword(raw['password']):
    params['error_password'] = settings.RE_PASSWORD_FAIL
    error = True
  elif raw['password'] != raw['verify']:
    params['error_verify'] = settings.RE_PASSWORD_MATCH
    error = True
  
  if not utils.validateEmail(raw['email']):
    params['error_email'] =  settings.RE_EMAIL_FAIL
    error = True
  
  return (error, params)
Esempio n. 2
0
def schedule_meeting(request):
    if request.method != 'POST':
        resp = {"status": "error", "message": "Method not allowed"}
        return HttpResponse(json.dumps(resp, indent=2))
    req_body = request.body.decode('utf-8')
    req_body = json.loads(req_body)
    title = req_body['title']
    note = req_body['note']
    time = req_body['time']
    user_emails = req_body['user_emails']
    if len(user_emails) < 2:
        resp = {
            'status': 'error',
            'message': 'Minimum 2 users in email required'
        }
        return HttpResponse(json.dumps(resp, indent=2))
    email_valid = True
    for email in user_emails:
        email_valid = email_valid and validateEmail(email)
    if email_valid == False:
        resp = {'status': 'error', 'message': 'invalid email ID'}
        return HttpResponse(json.dumps(resp, indent=2))
    for email in user_emails:
        User.objects.get_or_create(email=email, username=email)
    meeting = Meeting(title=title, note=note, time=time)
    meeting.save()
    users = User.objects.filter(email__in=user_emails)
    for user in users:
        invite = Invite(user=user, meeting=meeting)
        invite.save()
        resp = {'status': 'success', 'meeting': meeting.serialize()}
    return HttpResponse(json.dumps(resp, cls=DjangoJSONEncoder, indent=2))
Esempio n. 3
0
def sbp_validator(omhe_value):
    valdict={}
    if validateEmail(omhe_value):
        valdict['sbp_to']=omhe_value
    else:
        error_msg="The email address '%s'did not validate." % (omhe_value)
        raise InvalidValueError(error_msg)

    return valdict
Esempio n. 4
0
def sbp_validator(omhe_value):
    valdict = {}
    if validateEmail(omhe_value):
        valdict['sbp_to'] = omhe_value
    else:
        error_msg = "The email address '%s'did not validate." % (omhe_value)
        raise InvalidValueError(error_msg)

    return valdict
Esempio n. 5
0
 def post(self):
   try:
     nom = self.request.POST.get('nom')
     email = self.request.POST.get('email')
     tel = self.request.POST.get('tel')
     message = self.request.POST.get('message')
     if nom and email and message:
       if utils.validateEmail(email):
         email_template_path = os.path.join(os.path.dirname(__file__), 'templates/email_message.html')
         html_body = template.render(email_template_path, {'nom': nom,
                                                           'email': email,
                                                           'tel': tel,
                                                           'message': message})
         mail.send_mail(sender='Faster\'s energy <*****@*****.**>', 
                        to='*****@*****.**',
                        subject='Message de la part de ' + nom,
                        body=html_body,
                        html=html_body)
         path = os.path.join(os.path.dirname(__file__), 'templates/contactez-nous.html')
         response_text = template.render(path, {'init': False,
                                                'success': True,
                                                'response': u'Message envoyé.'})
       else:
         path = os.path.join(os.path.dirname(__file__), 'templates/contactez-nous.html')
         response_text = template.render(path, {'init': False,
                                                'success': False,
                                                'nom':nom,
                                                'email':email,
                                                'tel': tel,
                                                'message': message,
                                                'response': u'L\'email renseigné n\'est pas valide.'})
     else:
       if not nom:
         response = u'Le nom est obligatoire.'
       elif not email:
         response = u'L\'email est obligatoire.'
       elif not message:
         response = u'Vous devez mettre un message.'
       path = os.path.join(os.path.dirname(__file__), 'templates/contactez-nous.html')
       response_text = template.render(path, {'init': False,
                                              'success': False,
                                              'nom':nom,
                                              'email':email,
                                              'tel': tel,
                                              'message': message,
                                              'response': response})
   except:
     logging.error('Message.post - Error : ' + traceback.format_exc())
     self.error(500)
     response_text = utils.getErrorTemplate(500)
   self.response.out.write(response_text)
Esempio n. 6
0
def get_tasks():
    if request.method == 'POST':
        from_user = request.form['email']
        if not validateEmail(from_user):
            return jsonify({'status': 500, 'msg': '发送失败,邮箱地址不合法'}), 500
        title = request.form['title']
        msg = request.form['msg']
        try:
            email_body = '''
            发送者:{from_user}
            标题:{title}
            内容:{msg}
            '''.format(title=title, msg=msg, from_user=from_user)
            send_email(['*****@*****.**'], title, email_body)
            return jsonify({'status': 200, 'msg': '发送成功'}), 200
        except Exception as e:
            print(e)
            return jsonify({'status': 500, 'msg': '发送失败'}), 500
Esempio n. 7
0
 def create_user(self, request):
     """Create a User. Requires a unique username"""
     if User.query(User.name == request.user_name).get():
         raise endpoints.ConflictException(
                 'A User with that name already exists!')
     # Validate request.user_name is alphanumeric
     if not str(request.user_name).isalnum():
         raise endpoints.BadRequestException(
                 'User name must be alphanumeric')
     # If email address is given, validate it.
     email = ''
     if not getattr(request, 'email') == None:
         email = str(getattr(request, 'email'))
     if len(email) > 0:
         if not validateEmail(email):
             raise endpoints.BadRequestException(
                 'The given email is invalid!')
     user = User(name=request.user_name, email=email)
     user.put()
     return StringMessage(message='User {} created!'.format(
             request.user_name))
Esempio n. 8
0
 def clean(self):
     #validate field mainly for email
     if not utils.validateEmail(self.email):
         raise Exception,'email format wrong'
Esempio n. 9
0
 def clean(self):
     #validate field mainly for email
     if not utils.validateEmail(self.email):
         raise Exception, 'email format wrong'