Ejemplo n.º 1
0
 def __before__(self, action):
     if self.requires_auth:
        if 'user' not in session:               
            session['path_before_login'] = request.path_info +"?"
            for key, value in request.params.iteritems():
                session['path_before_login']+= str(key +"=" + value + "&")
            session.save()
            return redirect_to(h.url_for(controller='login'))
        else:
            self.user=session['user']
Ejemplo n.º 2
0
 def update_user_data(self):
     """Commit updated user info to database in response to a user form submittal."""
     self.setup()
     if request.params.has_key('reset_password'):
         c.jscript="confirmed=confirm('Reset password and send e-mail for user "+request.params['userid'] +"?');"+"window.location='" + \
            h.url_for(controller='administration',
                   action='update_user_data')+"?confirmed='+confirmed;"
         self.user=calypso.db.session.query(calypso.users.User).filter_by(userid=request.params['olduserid']).one()
         self.user.password=hashlib.md5('default').hexdigest()
         #inform user via email
         msg = email.mime.text.MIMEText('Your password to Calypso has been reset to the default.  Please change it as soon as possible.')
         msg['Subject'] = 'Calypso passowrd reset'
         msg['From'] = '*****@*****.**'
         msg['To'] = self.user.email
         if self.user.email!='':
             s = smtplib.SMTP()
             s.connect('localhost')
             s.sendmail('*****@*****.**',
                        self.user.email,
                        msg.as_string())
             s.quit()
         c.message="Password successfully reset to default"
         return render(ADMIN_HOME)
     elif request.params.has_key('confirmed'):
         if request.params['confirmed']=='true':
             calypso.db.session.sqlsession.commit()
             c.message="User data has been updated"
         else:
             return self.edit_user(AdministrationController.user.userid)
     else:
         self.user=calypso.db.session.query(calypso.users.User).filter_by(userid=request.params['olduserid']).one()
         self.user.userid=request.params['userid']
         self.user.firstname=request.params['firstname']
         self.user.lastname = request.params['lastname']
         if request.params.has_key('email'):
             self.user.email=request.params['email']
         AdministrationController.user=self.user
         c.jscript="confirmed=confirm('Really update information for user "+request.params['userid'] +"?');"+"window.location='" + h.url_for(controller='administration',
                                                                                                                                              action='update_user_data')+"?confirmed='+confirmed;"
     return render(ADMIN_HOME)
Ejemplo n.º 3
0
 def delete_user(self):
     self.setup()
     userid=request.params['userid']
     if userid=='admin':
         return render('derived/administration.html')
     if request.params.has_key('confirmed'):
         user=calypso.db.session.query(calypso.users.User).filter_by(userid=userid).one()
         if request.params['confirmed']=='true':
             calypso.db.session.delete(user)
             c.message="User with id " + userid + " has been deleted"
             self.setup()
             return render(ADMIN_HOME)
         else:
             return self.list_all_users()
     else:
         c.users = calypso.db.session.query(calypso.users.User).all()
         c.body = render('/derived/user_list.html')
         c.jscript="confirmed=confirm('Really delete user with id " + \
                    userid + "?');"+"window.location='" + \
            h.url_for(controller='administration',
                      action='delete_user') + \
                      "?confirmed='+confirmed+'&userid=" + \
                      userid + "';"
         return render(ADMIN_HOME)