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 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 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()