Esempio n. 1
0
def code():
  p['mode'] = 'code'
  p.template = 'change_password.tpl'

  if 'post' not in p.form:
    return

  if not len(p.form.getvalue('c_username', '')):
    p['errors']['c_username'] = '******'

  if not len(p.form.getvalue('c_email', '')):
    p['errors']['c_email'] = 'E-posta adresi boş bırakılamaz.'
  elif not re.match('^[A-Za-z0-9_\.-]+@([A-Za-z0-9]+(\-*[A-Za-z0-9]+)*\.)+[A-Za-z]{2,4}$', p.form.getvalue('c_email')):
    p['errors']['c_email'] = 'E-posta adresi geçerli formatta olmalı.'

  if not len(p['errors']):
    q = """SELECT uid
           FROM users
           WHERE
             email=%s AND
             username=%s"""
    uid = p.db.scalar_query(q, (p.form.getvalue('c_email'),
                                p.form.getvalue('c_username')))
    if not uid:
      p['errors']['c_email'] = 'Hatalı e-posta adresi ya da kullanıcı adı.'
    else:
      acode = pass_hash(str(random.random()))
      list = {
              'uid': uid,
              'code': acode,
              'timeB': sql_datetime(now())
              }
      p.db.insert('users_passcodes', list)
      
      # E-posta gönder
      t = "Pardil - Şifre Değiştirme Kodu"
      list = {
              'link': site_config['url'] + 'change_password.py?action=change',
              'code': acode,
              'time': num2str(site_config['activation_timeout'])
              }
      b = build_template(site_config['path'] + 'templates/email/change_password.tpl', list)
      sendmail(site_config['mail'], p.form.getvalue('c_email'), t, b)

      p['time'] = num2str(site_config['activation_timeout'])
      p['mode'] = 'change'
Esempio n. 2
0
def register():
  p.template = 'register.tpl'

  # Kullanıcı adını kontrol et.
  if not len(p.form.getvalue('r_username', '')):
    p['errors']['r_username'] = '******'
  elif not re.match('^[a-zA-Z0-9]{4,32}$', p.form.getvalue('r_username')):
    p['errors']['r_username'] = '******'
  else:
    q = """SELECT Count(*)
           FROM users
           WHERE username=%s"""
    q2 = """SELECT Count(*)
            FROM users_pending
            WHERE username=%s"""
    if p.db.scalar_query(q, p.form.getvalue('r_username')) > 0:
      p['errors']['r_username'] = '******'
    elif p.db.scalar_query(q2, p.form.getvalue('r_username')) > 0:
      p['errors']['r_username'] = '******'
   
  # E-posta adresini kontrol et.
  if not len(p.form.getvalue('r_email', '')):
    p['errors']['r_email'] = 'E-posta adresi boş bırakılamaz.'
  elif not re.match('^[A-Za-z0-9_\.-]+@([A-Za-z0-9]+(\-*[A-Za-z0-9]+)*\.)+[A-Za-z]{2,4}$', p.form.getvalue('r_email')):
    p['errors']['r_email'] = 'E-posta adresi geçerli formatta olmalı.'
  else:
    q = """SELECT Count(*)
           FROM users
           WHERE email=%s"""
    if p.db.scalar_query(q, p.form.getvalue('r_email')) > 0:
      p['errors']['r_email'] = 'E-posta adresi başkası tarafından kullanılıyor.'
      
  # Parolayı kontrol et.
  if not len(p.form.getvalue('r_password', '')) or not len(p.form.getvalue('r_password2', '')):
    p['errors']['r_password'] = '******'
  elif p.form.getvalue('r_password') != p.form.getvalue('r_password2'):
    p['errors']['r_password'] = '******'
  elif not re.match('^.{6,10}$', p.form.getvalue('r_password')):
    p['errors']['r_password'] = '******'
      
  # Hiç hata yoksa...
  if not len(p['errors']):

    
    # "Users - Pending" tablosuna ekle
    act_code = pass_hash(str(random.random()))
    list = {
            'username': p.form.getvalue('r_username'),
            'password': pass_hash(p.form.getvalue('r_password')),
            'email': p.form.getvalue('r_email'),
            'timeB': sql_datetime(now()),
            'code': act_code
            }
    p.db.insert('users_pending', list)


    # E-posta gönder

    t = "Pardil - Üyelik Aktivasyonu"
    list = {
            'link': site_config['url'] + 'activate.py?code=' + act_code,
            'time': num2str(site_config['activation_timeout'])
            }
    b = build_template(site_config['path'] + 'templates/email/register.tpl', list)
    sendmail(site_config['mail'], p.form.getvalue('r_email'), t, b)

    p['time'] = num2str(site_config['activation_timeout'])
    p.template = "register.done.tpl"