def resendconfirmation(): if authapi.is_authenticated(): return redirect(url_for('.profile')) email = request.form['email'] user = User.query.filter_by(email=email).one() if user: utils.send_welcome_email(user) flash(_(u"The confirmation email was sent")) else: flash(_(u"User not found")) return redirect(url_for('auth.login'))
def signup(): """Renders the signup form""" if authapi.is_authenticated(): return redirect(url_for('.profile')) # default_data=None ret_code = -1 form = social(SignupForm) print "CADASTRANDO" #form = SignupForm() fromsocial = request.cookies.get('connect_type') in ('social_f','social_t') form.social = fromsocial print "VALIDANDO" if request.method == 'POST' and form.validate_on_submit(): print "VALIDADO!" try: meta = form.meta dget = meta.pop if fromsocial: print "\nsenha fromsocial" password = "" else: password = dget('password') print "\nsenha", password # Finally, it's time to create the user email = dget('email') username = email if request.cookies.get('connect_type') == 'social_t': username = session['tmp_twitter_id'] # if request.cookies.get('connect_type') == 'social_f': # username = dget('fbid') # print "FACEBOOK ID =", username user = authapi.create_user( dget('name'), username, password, email, form.meta, dget('receive_sms'), dget('receive_email') ) if fromsocial: if request.cookies.get('connect_type') == 'social_t': user.set_meta('twitter', session['tmp_twitter_id']) user.set_meta('twitteruser', True) dbsession.commit() if request.cookies.get('connect_type') == 'social_f': user.set_meta('facebookuser', True) dbsession.commit() utils.send_welcome_email(user) flash(_(u'Your user was registered with successful!'), 'alert-success') ret_code = 0 except authapi.UserExists: flash( _(u'User already exists'), 'alert-error') ret_code = 1 except authapi.UserExistsUnconfirmed: flash( _(u'User already exists, but need confirmation'), 'alert-error') ret_code = 4 except authapi.EmailAddressExists: flash(_(u'The email address informed is being used by another person'), 'alert-error') ret_code = 2 else: if request.method == 'POST' : print form.errors # for errorMessages, fieldName in enumerate(form.errors): # print errorMessages, fieldName # for err in errorMessages: # # do something with your errorMessages for fieldName # flash( "%s - %s" % (fieldName,err),'alert-error') flash(_(u'Correct the validation errors and resend'),'alert-error') ret_code = 3 tos = fromcache('tossigin') or tocache('tossigin',wordpress.getPageByPath('tos')) rm = fromcache('moresigin') or tocache('moresigin',wordpress.getPageByPath('signup-read-more')) menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') ) try: twitter_hash_cabecalho = utils.twitts() except KeyError: twitter_hash_cabecalho = "" return render_template( 'signup.html', form=form, readmore=rm,tos=tos, menu=menus, twitter_hash_cabecalho=twitter_hash_cabecalho, sidebar=wordpress.getSidebar, ret_code=ret_code )
def contribui(slug): obra = fromcache("obra-" + slug) or tocache("obra-" + slug, _get_obras(slug)[0]) if not obra: return abort(404) r = {'status':'ok', 'message':'Sua contibuição foi aceita com sucesso'} user_recent = False if not authapi.is_authenticated(): # r = {'status':'not_logged'} """ Se não está autenticado, tenta achar o usuário pelo email, e acessar com a senha inserida no formulario. Se não, cadastra o camarada, com o nome e email informados, gerando uma senha para ele e enviando o email de boas vindas. """ email = request.form['email'] if request.form['senha']: #Informou a senha do cadastro já existente # username = email # senha = request.form['senha'] #Efetua o login print "Usuario e senha informado... logando!" username = request.values.get('email') senha = request.values.get('senha') print "tentando logar com", username, senha try: user = authapi.login(username, senha) r = {'status':'ok', 'message':'Sua contibuição foi aceita com sucesso', 'refresh': True} except authapi.UserNotFound: r = {'status':'nok', 'message':_(u'Wrong user or password')} return dumps(r) except authapi.UserAndPasswordMissmatch: r = {'status':'nok', 'message':_(u'Wrong user or password')} return dumps(r) elif request.form['nome']: print "Nome informado... cadastrando..." #Informou a senha para cadastro nome = request.form['nome'] telefone = request.form['telefone'] if 'telefone' in request.form else "" novasenha = request.form['newPassword'] if 'newPassword' in request.form else "" if not novasenha: # novasenha = "gabinetedigital" novasenha = ''.join(random.choice(string.printable) for x in range(8)) # print nome, '-', email, '-', novasenha try: user = authapi.create_user(nome, email, unicode(novasenha), email) r = {'status':'ok', 'message':'Sua contibuição foi aceita com sucesso. Verifique seu email para confirmar o cadastro.'} user_recent = True send_welcome_email(user) send_password(user.email, novasenha) except authapi.UserExistsUnconfirmed, e: r = {'status':'nok', 'message':u'Seu usuário precisa ser confirmado, veja seu email!'} return dumps(r) if telefone: user.set_meta('phone', telefone) dbsession.commit() else: r = {'status':'nok', 'message':u'É necessário informar uma senha ou dados para cadastro.'}
def signup(): """Renders the signup form""" if authapi.is_authenticated(): return redirect(url_for('.profile')) # default_data=None ret_code = -1 form = social(SignupForm) print "CADASTRANDO" #form = SignupForm() fromsocial = request.cookies.get('connect_type') in ('social_f','social_t') form.social = fromsocial print "VALIDANDO" if request.method == 'POST' and form.validate_on_submit(): print "VALIDADO!" try: meta = form.meta dget = meta.pop if fromsocial: print "\nsenha fromsocial" password = "" else: password = dget('password') print "\nsenha", password # Finally, it's time to create the user email = dget('email') username = email if request.cookies.get('connect_type') == 'social_t': username = session['tmp_twitter_id'] # if request.cookies.get('connect_type') == 'social_f': # username = dget('fbid') # print "FACEBOOK ID =", username user = authapi.create_user( dget('name'), username, password, email, form.meta, dget('receive_sms'), dget('receive_email') ) if fromsocial: if request.cookies.get('connect_type') == 'social_t': user.set_meta('twitter', session['tmp_twitter_id']) user.set_meta('twitteruser', True) dbsession.commit() if request.cookies.get('connect_type') == 'social_f': user.set_meta('facebookuser', True) dbsession.commit() utils.send_welcome_email(user) flash(_(u'Your user was registered with successful!'), 'alert-success') ret_code = 0 except authapi.UserExists: flash( _(u'User already exists'), 'alert-error') ret_code = 1 except authapi.UserExistsUnconfirmed: flash( _(u'User already exists, but need confirmation'), 'alert-error') ret_code = 4 except authapi.EmailAddressExists: flash(_(u'The email address informed is being used by another person'), 'alert-error') ret_code = 2 else: if request.method == 'POST' : print form.errors # for errorMessages, fieldName in enumerate(form.errors): # print errorMessages, fieldName # for err in errorMessages: # # do something with your errorMessages for fieldName # flash( "%s - %s" % (fieldName,err),'alert-error') flash(_(u'Correct the validation errors and resend'),'alert-error') ret_code = 3 tos = fromcache('tossigin') or tocache('tossigin',wordpress.getPageByPath('tos')) rm = fromcache('moresigin') or tocache('moresigin',wordpress.getPageByPath('signup-read-more')) menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') ) try: twitter_hash_cabecalho = utils.twitts() except KeyError: twitter_hash_cabecalho = "" return render_template( 'signup.html', form=form, readmore=rm,tos=tos, menu=menus, twitter_hash_cabecalho=twitter_hash_cabecalho, ret_code=ret_code )
def contribui(slug): obra = fromcache("obra-" + slug) or tocache("obra-" + slug, _get_obras(slug)[0]) if not obra: return abort(404) r = {'status': 'ok', 'message': 'Sua contibuição foi aceita com sucesso'} user_recent = False if not authapi.is_authenticated(): # r = {'status':'not_logged'} """ Se não está autenticado, tenta achar o usuário pelo email, e acessar com a senha inserida no formulario. Se não, cadastra o camarada, com o nome e email informados, gerando uma senha para ele e enviando o email de boas vindas. """ email = request.form['email'] if request.form['senha']: #Informou a senha do cadastro já existente # username = email # senha = request.form['senha'] #Efetua o login print "Usuario e senha informado... logando!" username = request.values.get('email') senha = request.values.get('senha') print "tentando logar com", username, senha try: user = authapi.login(username, senha) r = { 'status': 'ok', 'message': 'Sua contibuição foi aceita com sucesso', 'refresh': True } except authapi.UserNotFound: r = {'status': 'nok', 'message': _(u'Wrong user or password')} return dumps(r) except authapi.UserAndPasswordMissmatch: r = {'status': 'nok', 'message': _(u'Wrong user or password')} return dumps(r) elif request.form['nome']: print "Nome informado... cadastrando..." #Informou a senha para cadastro nome = request.form['nome'] telefone = request.form[ 'telefone'] if 'telefone' in request.form else "" novasenha = request.form[ 'newPassword'] if 'newPassword' in request.form else "" if not novasenha: # novasenha = "gabinetedigital" novasenha = ''.join( random.choice(string.printable) for x in range(8)) # print nome, '-', email, '-', novasenha try: user = authapi.create_user(nome, email, unicode(novasenha), email) r = { 'status': 'ok', 'message': 'Sua contibuição foi aceita com sucesso. Verifique seu email para confirmar o cadastro.' } user_recent = True send_welcome_email(user) send_password(user.email, novasenha) except authapi.UserExistsUnconfirmed, e: r = { 'status': 'nok', 'message': u'Seu usuário precisa ser confirmado, veja seu email!' } return dumps(r) if telefone: user.set_meta('phone', telefone) dbsession.commit() else: r = { 'status': 'nok', 'message': u'É necessário informar uma senha ou dados para cadastro.' }