def index(self,id=''): if id > 0: c.person = person.Person.get(c.user.site_id,id) c.activities = Activity.activity_by_person(c.user.site_id,id) c.activities_by_day = Activity.stats_by_person(c.user.site_id,id) c.categories = Activity.categories(c.user.site_id,id) return render('/activity.html')
def signin_POST(self,id=0): log.info('made it to account signin_POST?' ) if 'email' in self.request.arguments: user = meta.DBSession.query(Person).filter_by( email=self.get_argument('email').lower()).first() if user is None: self.add_error("We were not able to verify that email\ or password, please try again") elif 'password' in self.request.arguments: if user.is_authenticated(self.get_argument('password')): a = Activity(site_id=user.site_id,person_id=user.id,activity='Logging In') #a.ref_url = 'comment url' a.category = 'account' a.ip = self.request.remote_ip a.save() remember_me = False if 'remember_me' in self.request.arguments: remember_me = True self.set_current_user(user,is_authenticated = True,remember_me=remember_me,islogon=True) return self.redirect("/dashboard") else: self.add_error("We were not able to verify that \ email or password, please try again") else: self.add_error("You did not submit a password, please try again.") else: self.add_error("You need to enter an email and password to signin.") self.render('/user/signin.html')
def inviteusers_POST(self): """ admin is sending out a number of invites to users """ if 'emails' in request.POST: emails = request.POST['emails'] delay = 4 from demisauce.lib import scheduler for email in emails.split(','): email = email.strip().lower() user = Person.by_email(c.user.site_id,email) if user is None: user = Person(site_id=c.site_id,email=email, displayname=email) user.save() #send emails url2 = urllib.quote_plus('/account/viewh/%s' % (user.hashedemail)) dnew = {} dnew['link'] = '%s/account/verify?unique=%s&node=%s&return_url=%s' %\ (base_url(),user.user_uniqueid,user.id,url2) dnew['from'] = c.user.displayname a = Activity(site_id=user.site_id,person_id=user.id,activity='sending email invite') a.ref_url = 'account admin invite' a.category = 'account' a.save() scheduler.add_interval_task(send_emails,0,('invitation_to_demisauce',[user.email],dnew) , initialdelay=delay) delay += 3 return 'from form %s' % emails return 'error'
def signin_POST(self): if 'email' in request.POST: user = meta.DBSession.query(Person).filter_by( email=request.POST['email'].lower()).first() if user is None: h.add_error("We were not able to verify that email\ or password, please try again") elif 'password' in request.POST: if user.is_authenticated(request.POST['password']): a = Activity(site_id=user.site_id,person_id=user.id,activity='Logging In') #a.ref_url = 'comment url' a.category = 'account' a.save() remember_me = False if 'remember_me' in request.POST: remember_me = True self.start_session(user,remember_me=remember_me) return self.returnurl_orgoto(controller='dashboard') else: h.add_error("We were not able to verify that \ email or password, please try again") else: h.add_error("You did not submit a password, please try again.") else: h.add_error("You need to enter an email and password to signin.") return render('/account/signin.html')
def get(self,site_slug='',format="json"): if not self.user and 'hashedemail' in self.request.arguments: user = user.Person.by_hashedemail(str(self.get_argument('hashedemail'))) elif self.user: user = self.user else: return if 'site_slug' in self.request.arguments: site_slug = str(self.get_argument('site_slug')) if 'activity' in self.request.arguments: activity_name = str(self.get_argument('activity')) a = Activity(site_id=user.site_id,person_id=user.id,activity=activity_name) a.ip = self.request.remote_ip if 'ref_url' in self.request.arguments: a.ref_url = self.get_argument('ref_url') if 'category' in self.request.arguments: a.category = self.get_argument('category') if 'cnames' in self.request.arguments: names = [n for n in self.get_argument('cnames').split(',') if n != ''] if len(names) > 0: a.custom1name = names[0] a.custom1val = request.params[names[0]] if len(names) > 1: a.custom2name = names[1] a.custom2val = request.params[names[1]] a.save()
def index(self,id=''): if id > 0: person = Person.get(self.user.site_id,id) activities = Activity.activity_by_person(self.user.site_id,id) activities_by_day = Activity.stats_by_person(self.user.site_id,id) categories = Activity.categories(self.user.site_id,id) return self.render('/activity.html',person=person,activities=activities, activities_by_day=activities_by_day,categories=categories) else: self.write("no id? %s" % id)
def _view(self,person,getcomments=False): c.person = None if person: c.person = person #TODO, somehow filter by site???? this gets ALL if getcomments: c.comments = person.recent_comments(5) c.helptickets = c.person.help_tickets() c.activities_by_day = Activity.stats_by_person(person.site_id,person.id) if c.user is None: pass elif c.user is not None and c.user.issysadmin: pass elif c.user is not None and c.user.isadmin: pass else: if c.user.site_id == c.person.site_id: pass else: c.person = None c.comments = None else: pass #TODO: raise error, or bad page c.base_url = config['demisauce.url'] return render('/account/settings.html')
def interest(self,id=0): """ User has selected to enter an email to be on waitinglist """ log.debug(self.request.arguments) form = SignupForm(QueryDict(self.request.arguments)) log.debug(form.data) if 'email' in self.request.arguments and form.validate(): user = meta.DBSession.query(Person).filter_by( email=self.get_argument("email").lower()).first() if user is None: new_email = form.email.data.lower() site = Site(name=new_email,email=new_email) site.save() user = Person(site_id=site.id,email=new_email, displayname=new_email) user.slug = user.hashedemail user.save() a = Activity(site_id=user.site_id,person_id=user.id,activity='Signup Interest Form') #a.ref_url = 'comment url' a.ip = self.request.remote_ip a.category = 'account' a.save() link = '%s/user/verify?unique=%s&node=%s&return_url=%s' %\ (options.base_url, user.user_uniqueid, user.id, urllib.quote_plus('/user/viewh/%s' % (user.hashedemail))) json_dict = { 'emails':[user.email], 'template_name':'thank_you_for_registering_with_demisauce', 'template_data':{ 'link':link, 'displayname':user.displayname, 'email':user.email, 'title':'welcome' } } self.db.gearman_client.do_task(Task("email_send",json.dumps(json_dict), background=True)) self.add_alert("Thank You!") self.redirect("/") return self.render('/user/signup.html',form=form)
def interest(self): """ User has selected to enter an email to be on waitinglist """ if 'email' in request.POST: user = meta.DBSession.query(Person).filter_by( email=request.POST['email'].lower()).first() if user is None: site = Site(name=self.form_result['email'],email=self.form_result['email']) site.save() user = Person(site_id=site.id,email=self.form_result['email'], displayname=self.form_result['email']) user.slug = user.hashedemail user.save() a = Activity(site_id=user.site_id,person_id=user.id,activity='Signup Interest Form') #a.ref_url = 'comment url' a.category = 'account' a.save() #TODO: refactor/extract email send to trigger event api #send emails url2 = urllib.quote_plus('/account/viewh/%s' % (user.hashedemail)) delay = 4 from demisauce.lib import scheduler dnew = {} dnew['link'] = '%s/account/verify?unique=%s&node=%s&return_url=%s' %\ (c.base_url,user.user_uniqueid,user.id,url2) dnew['displayname'] = user.displayname dnew['email'] = user.email dnew['title'] = 'welcome' scheduler.add_interval_task(send_emails,0,('thank_you_for_registering_with_demisauce', [user.email],dnew) , initialdelay=delay) if 'demisauce.admin' in config: scheduler.add_interval_task(send_emails,0,('a-new-user-has-registered', [config['demisauce.admin']],dnew) , initialdelay=8) h.add_alert("Thank You!") return redirect_wsave(controller='home',action='index') else: h.add_error("You need to enter an email.") return render('/account/signup.html')
def signin(self): log.info('made it to account signin?' ) if c.user: redirect_to(controller="home", action='index') elif 'userkey' in request.cookies: user = meta.DBSession.query(Person).filter_by( user_uniqueid=request.cookies['userkey'].lower()).first() if not user is None: a = Activity(site_id=user.site_id,person_id=user.id,activity='Logging In') #a.ref_url = 'comment url' a.category = 'account' self.start_session(user) return self.returnurl_orgoto(controller='home',action='index') if 'email' in request.cookies: c.email = request.cookies['email'].lower() session.clear() from demisauce.controllers.comment import google_auth_url c.google_auth_url = google_auth_url('%s/account/settings' % config['demisauce.url']) return render('/account/signin.html')
def signin(self,id=0): log.info('made it to account signin?' ) email = None if self.get_current_user(): return self.redirect("/home/index") elif 'dsuserkey' in self.cookies: user = meta.DBSession.query(Person).filter_by( user_uniqueid=self.get_cookie('dsuserkey').lower()).first() if user: a = Activity(site_id=user.site_id,person_id=user.id,activity='Logging In') #a.ref_url = 'comment url' a.category = 'account' a.ip = self.request.remote_ip self.set_current_user(user) return self.redirect('/home/default') if 'email' in self.cookies: email = self.get_cookie('email').lower() googleurl = google_auth_url('%s/user/usersettings' % options.base_url) self.render('/user/signin.html',google_auth_url=googleurl,email=email)
def _view(self,person,getcomments=False): if person: helptickets = None #person.help_tickets() activities_by_day = Activity.stats_by_person(person.site_id,person.id) activity_count = len(activities_by_day) if self.user is None: pass elif self.user is not None and self.user.issysadmin: pass elif self.user is not None and self.user.isadmin: pass else: if self.user.site_id == person.site_id: pass else: person = None else: pass #TODO: raise error, or bad page self.render('/user/settings.html',person=person, activities_by_day=activities_by_day,activity_count=activity_count)