def post(self): """sent email to admin of sosbeacon school""" from sosbeacon.user import forgot_password email = self.request.POST['email'] if not email: out = self.render('forgot_password.mako', is_loggedin=False, message="Please enter your email address.") self.response.out.write(out) return user_key = User.query(User.email == email) user = user_key.get() if user: forgot_password(user) out = self.render('forgot_password.mako', is_loggedin=False, message="Your new password has been sent to you by email message. " "You will now be returned to where you were before.") self.response.out.write(out) else: out = self.render('forgot_password.mako', is_loggedin=False, message=""" You have not entered a email address that we recognize, or your account has not been activated or you have not set a password in settings in your SOSbeacon app on your mobile phone. Please try again. """) self.response.out.write(out)
def post(self): """sent email to admin of sosbeacon school""" from sosbeacon.user import forgot_password email = self.request.POST['email'] if not email: out = self.render('forgot_password.mako', is_loggedin=False, message="Please enter your email address.") self.response.out.write(out) return user_key = User.query(User.email == email) user = user_key.get() if user: forgot_password(user) out = self.render( 'forgot_password.mako', is_loggedin=False, message= "Your new password has been sent to you by email message. " "You will now be returned to where you were before.") self.response.out.write(out) else: out = self.render('forgot_password.mako', is_loggedin=False, message=""" You have not entered a email address that we recognize, or your account has not been activated or you have not set a password in settings in your SOSbeacon app on your mobile phone. Please try again. """) self.response.out.write(out)
def post(self, *args, **kwargs): if not 'u' in self.session: email = self.request.POST['email'] password = self.request.POST['password'] user = User.query(ndb.AND(User.email == email), namespace='_x_') if user.get() is None: self.render_user_login(is_loggedin=False, error='Email or Password is wrong!.') return if user.get().is_admin: self.render_user_login(is_loggedin=False, error='Email or Password is wrong!.') return else: if check_password_hash(password, user.get().password): self.delete_session() self.set_current_user(user) else: self.render_user_login( is_loggedin=False, error='Email or Password is wrong!.') return user_key = self.session.get('u') user = ndb.Key(urlsafe=user_key).get() school_length = len(user.schools) #check schools that user was asigned if school_length == 1: school_key = user.schools[0] school_key = school_key.get().key.urlsafe() self.set_current_school(school_key) self.redirect("/") return if school_length == 0: self.render_user_login( is_loggedin=False, error= "You don't have any schools!. Please contact with admin for this reason." ) self.delete_session() return if school_length > 1 and 'school' not in self.request.POST: schools = [school_key.get() for school_key in user.schools] self.render_user_login(is_loggedin=True, schools=schools) return school_key = self.request.POST['school'] self.set_current_school(school_key) self.redirect("/")
def process_post_user(request, schema, entity): from voluptuous import Schema from sosbeacon.student import create_default_student from sosbeacon.user import send_invitation_email obj = json.loads(request.body) schema = Schema(schema, extra=True) if obj['email'] == '' or obj['phone'] == '' or \ obj['first_name'] == '' or obj['last_name'] == '': return False if len(obj['password']) < 6: return False #check user exits check_email = User.query(User.email == obj['email'], namespace='_x_') check_phone = User.query(User.phone == obj['phone'], namespace='_x_') if check_email.get() or check_phone.get(): return False try: obj = schema(obj) except: logging.exception('validation failed') logging.info(obj) user = entity.from_dict(obj) user.set_password(obj['password']) to_put = [user] ndb.put_multi(to_put) create_default_student(user) send_invitation_email(user.first_name + " " + user.last_name, user.email, obj['password']) return user
def process_post_user(request, schema, entity): from voluptuous import Schema from sosbeacon.student import create_default_student from sosbeacon.user import send_invitation_email obj = json.loads(request.body) schema = Schema(schema, extra=True) if obj['email'] == '' or obj['phone'] == '' or \ obj['first_name'] == '' or obj['last_name'] == '': return False if len(obj['password']) < 6: return False #check user exits check_email = User.query(User.email == obj['email'], namespace = '_x_') check_phone = User.query(User.phone == obj['phone'], namespace = '_x_') if check_email.get() or check_phone.get(): return False try: obj = schema(obj) except: logging.exception('validation failed') logging.info(obj) user = entity.from_dict(obj) user.set_password(obj['password']) to_put = [user] ndb.put_multi(to_put) create_default_student(user) send_invitation_email(user.first_name + " " + user.last_name, user.email, obj['password']) return user
def post(self, *args, **kwargs): if not 'u' in self.session: email = self.request.POST['email'] password = self.request.POST['password'] user = User.query(ndb.AND(User.email == email), namespace = '_x_') if user.get() is None: self.render_user_login(is_loggedin = False, error='Email or Password is wrong!.') return if user.get().is_admin: self.render_user_login(is_loggedin = False, error='Email or Password is wrong!.') return else: if check_password_hash(password, user.get().password): self.delete_session() self.set_current_user(user) else: self.render_user_login(is_loggedin = False, error='Email or Password is wrong!.') return user_key = self.session.get('u') user = ndb.Key(urlsafe=user_key).get() school_length = len(user.schools) #check schools that user was asigned if school_length == 1: school_key = user.schools[0] school_key = school_key.get().key.urlsafe() self.set_current_school(school_key) self.redirect("/") return if school_length == 0: self.render_user_login(is_loggedin = False, error="You don't have any schools!. Please contact with admin for this reason.") self.delete_session() return if school_length > 1 and 'school' not in self.request.POST: schools = [school_key.get() for school_key in user.schools] self.render_user_login(is_loggedin = True, schools=schools) return school_key = self.request.POST['school'] self.set_current_school(school_key) self.redirect("/")
def post(self, *args, **kwargs): if not 'ad' in self.session: email = self.request.POST['email'] password = self.request.POST['password'] user = User.query(ndb.AND(User.email == email, User.is_admin == True), namespace = '_x_') if user.get() is None: self.render_admin_login(error='Email or Password is wrong!.') return else: if check_password_hash(password, user.get().password): self.setup_admin_session(user) else: self.render_admin_login(error='Email or Password is wrong!.') return self.redirect("/admin")
def post(self, *args, **kwargs): if not 'ad' in self.session: email = self.request.POST['email'] password = self.request.POST['password'] user = User.query(ndb.AND(User.email == email, User.is_admin == True), namespace='_x_') if user.get() is None: self.render_admin_login(error='Email or Password is wrong!.') return else: if check_password_hash(password, user.get().password): self.setup_admin_session(user) else: self.render_admin_login( error='Email or Password is wrong!.') return self.redirect("/admin")