def clean_code(self): code = self.cleaned_data["code"] error = check_verification(self.user, code) if error: log.warning("%s: code verification failed [%s]" % (self.user, error)) raise forms.ValidationError(error) send_message(User.objects.filter(pk=1)[0], "Welcome aboard ! Add some friends and start SMSing !", [self.user]) return code
def execute(self): user = User.objects.get(username__iexact=self.cleaned_data["username"]) new_pass = CreateCode(user) log.info("%s: Password has been reset to %s" % (user, new_pass)) user.set_password(new_pass) user.save() send_message( User.objects.filter(username="******")[0], "SMSKI: Your password has been reset to: %s" % new_pass, [user] )
def send_verification(phone, user): old_ver = PhoneVerification.objects.filter(user=user) # TODO: Handle flooding of verifications if old_ver: time_diff = (datetime.datetime.now() - old_ver[0].date).seconds if time_diff < 60 * 5: log.info("%s: User impatient, request ver only after %d seconds" % (user, time_diff)) return "Please give the sms %d more minutes to get there" % (5 - time_diff / 60) log.info("%s: Found old PhoneVerification, delete for now" % (user)) old_ver[0].delete() log.info("%s: Created new PhoneVerification and sending notification" % (user)) pv = PhoneVerification( user=user, phone=phone, code=CreateCode(user).lower(), attempt=1, date=datetime.datetime.now() ) pv.save() send_message(User.objects.filter(username="******")[0], "Your code for SMSKI is: %s" % pv.code, [user]) return ""
def parse_incoming_mail(string): ''' Get a new email and parse it ''' log.info('Parsing new email') # st = SMSTracker(date=datetime.datetime.now(), data=string, parsed=False) # st.save() msg = email.message_from_string(string) # Only SMS messages have a custom reply-to (with the number to reply to) if not 'Reply-To' in msg: log.info('Got an administrative email. Skipping') return else: log.info('--- New incoming SMS email ---') data = msg.get_payload() if not len(data): log.error('No payload !') exit() try: soup = BeautifulSoup(data) except: log.error('Error loading Soup') return # Get the sending phone number from the reply-to field try: reply_to = msg['Reply-To'] str = re.search('\++\d+ ([\d\-]+)', reply_to).group(1).replace('-','') except: log.error('Error getting number [%s]' % reply_to) return if not str: log.error('Error empty number [%s]' % reply_to) return try: num = int(str) except: log.error('Error converting to num [%s]' % str) return # Get the text try: str = soup.findAll('font')[2].string except: log.error('Error getting body') return try: body = re.sub('=\d.', '', str).strip() except: log.error('Error getting body [%s]' % str) return # st.parsed = True; # st.save() # Find the session str = re.search('[0-9]+', (msg['To']).split('@')[0]).group(0) try: session_id = int(str, 10) except: log.error('Error getting session id [%s]' % str) return if not session_id: log.error("Error getting session id from %s " % msg['To']) return ses = SMSSession.objects.filter(pk=session_id) if not len(ses): log.error("Error getting session with id %d" % session_id) return ses = ses[0] # Get source user log.info('Get user for %s' % msg['From']) by_num = int(re.sub('[^0-9]', '', msg['From'])[-9:]) if not by_num: log.error("Error parsing orig number %s" % msg['From']) return by_prof = Profile.objects.filter(phone=by_num) if not len(by_prof): log.error("Error getting using with num %d" % by_num) return by = by_prof[0].user log.info("Got message from %s to %s [%s]" % (by, ses.user, body)) body_w1255 = quopri.decodestring(body) decoded_body = body_w1255.decode('windows-1255').strip() send_message(by, decoded_body, [ses.user], phone_reply=True)
def action(self): send_message(self.user, self.cleaned_data["message"], self.cleaned_data["recipients"])