def api_note_add(request): """ summary: api interface post message params: GET['uname'] Tmitter user's username GET['pwd'] user's password not encoding GET['msg'] message want to post GET['from'] your web site name author: Jason Lee """ # get querystring params _username = request.GET['uname'] _password = function.md5_encode(request.GET['pwd']) _message = request.GET['msg'] _from = request.GET['from'] # Get user info and check user try: _user = User.objects.get(username=_username, password=_password) except: return HttpResponse("-2") # Get category info ,If it not exist create new (_cate, _is_added_cate) = Category.objects.get_or_create(name=_from) try: _note = Note(message=_message, user=_user, category=_cate) _note.save() return HttpResponse("1") except: return HttpResponse("-1")
def __check_login(_username, _password): _state = { 'success': True, 'message': 'none', 'userid': -1, 'realname': '', } try: _user = User.objects.get(username=_username) # to decide password if (_user.password == function.md5_encode(_password)): _state['success'] = True _state['userid'] = _user.id _state['realname'] = _user.realname else: # password incorrect _state['success'] = False _state['message'] = _('Password incorrect.') except (User.DoesNotExist): # user not exist _state['success'] = False _state['message'] = _('User does not exist.') return _state
def __do_signup(request, _userinfo): _state = { 'success': False, 'message': '', # 'userid': -1, } # check username exist if (_userinfo['email'] == ''): _state['success'] = False _state['message'] = _(u'请输入邮箱.') return _state if (_userinfo['password'] == ''): _state['success'] = False _state['message'] = _(u'请输入密码.') return _state # check username exist if (__check_email_exist(_userinfo['email'])): _state['success'] = False _state['message'] = _(u'用户已存在.') return _state # check password & confirm password if (_userinfo['password'] != _userinfo['confirm']): _state['success'] = False _state['message'] = _(u'密码确认有误.') return _state session_check_code = request.session['check_code'] if _userinfo['post_check_code'].lower() != session_check_code.lower(): _state['success'] = False _state['message'] = _(u'验证码有误.') return _state a = map("".join, list(itertools.product("abcdefghijklmnopqrstuvwxyz", repeat=5))) if request.META.has_key('HTTP_X_FORWARDED_FOR'): _userip = request.META['HTTP_X_FORWARDED_FOR'] else: _userip = request.META['REMOTE_ADDR'] _user = UserProfile(username=a[random.randint(0, 26**5 - 1)], password=function.md5_encode(_userinfo['password']), email=_userinfo['email'], url=_userinfo['email'], userip=_userip # area = Area.objects.get(id=1) ) # try: # _user.password = make_password(_userinfo['password']) _user.save() _state['success'] = True request.session['islogin'] = True request.session['userid'] = _user.id request.session['email'] = _userinfo['email'] request.session['userip'] = _userip send_regist_success_mail.delay(_userinfo) return _state
def api_note_add(request): # get querystring params _username = request.GET['uname'] _password = function.md5_encode(request.GET['pwd']) _message = request.GET['msg'] _from = request.GET['from'] # Get user info and check user try: _user = UserProfile.objects.get(username=_username, password=_password) except: return HttpResponse("-2") # Get category info ,If it not exist create new (_cate, _is_added_cate) = Category.objects.get_or_create(name=_from) try: _note = Note(message=_message, user=_user, category=_cate) _note.save() return HttpResponse("1") except: return HttpResponse("-1")
def __check_login(request, _email, _password): _state = {'success': False, 'message': 'none', 'userid': -1, 'userip': ''} try: _user = UserProfile.objects.get(email=_email) # to decide password if (_user.password == function.md5_encode(_password)): _state['success'] = True _state['userid'] = _user.id # if request.META.has_key('HTTP_X_FORWARDED_FOR'): # _state['userip'] = request.META['HTTP_X_FORWARDED_FOR'] # else: # _state['userip'] = request.META['REMOTE_ADDR'] else: # password incorrect _state['success'] = False _state['message'] = _(u'密码错误!') except (UserProfile.DoesNotExist): # user not exist _state['success'] = False _state['message'] = _(u'用户不存在!') return _state
def save(self, modify_pwd=True): if modify_pwd: self.password = function.md5_encode(self.password) self.about = formatter.substr(self.about, 20, True) super(User, self).save()