def post(self, request, format=None): email = request.POST.get('email', None) templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') if email is not None: try: user = Users.objects.get(email=request.POST['email']) except Users.DoesNotExist: user = None if user is not None: newpassword = ssoTokenGenerator(8) if user.id: user.password = newpassword user.save() subject = "Forget Password" #message="Forget Password Notification mail" #message+="<br> New password: " + newpassword message = render_to_string( templatePath + '/forget_password.html', { 'userid': user.id, 'email': user.email, 'newpassword': newpassword }) sendStatus = sendmail(subject, message, request.POST['email']) return json_response({ 'status': 'success', 'data': { 'newpassword': user.password, 'email': user.email, 'id': user.id, 'sendStatus': sendStatus, }, 'msg': 'An email has been sent on your email address with new password.' }) else: return json_response( { 'status': 'error', 'msg': 'Invalid User' }, status=status.HTTP_400_BAD_REQUEST) else: return json_response( { 'status': 'error', 'msg': 'Invalid Email' }, status=status.HTTP_400_BAD_REQUEST) else: return json_response({ 'status': 'error', 'msg': 'Invalid Data' }, status=400)
def post(self, request, format=None): email = request.POST.get('email', None) oldpassword = request.POST.get('oldpassword', None) newpassword = request.POST.get('newpassword', None) templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') if email is not None and oldpassword is not None: try: user = Users.objects.get(email=request.POST['email'], password=request.POST['oldpassword']) except Users.DoesNotExist: user = None if user is not None: if user.id: user.password = newpassword user.save() subject = "Password Changed" #message="Password Changed Notification mail" message = render_to_string( templatePath + '/change_password.html', { 'userid': user.id, 'email': user.email }) sendStatus = sendmail(subject, message, request.POST['email']) return json_response({ 'status': 'success', 'msg': 'User password changed successfully.', 'sendStatus': sendStatus, }) else: return json_response( { 'status': 'error', 'msg': 'Invalid User' }, status=status.HTTP_400_BAD_REQUEST) else: return json_response( { 'status': 'error', 'msg': 'Old password is incorrect' }, status=status.HTTP_400_BAD_REQUEST) else: return json_response({ 'status': 'error', 'msg': 'Invalid Data' }, status=400)
def post(self, request, format=None): userId = request.POST.get('userId', None) message = request.POST.get('message', None) templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') baseUrl = settings.BASE_URL + settings.STATIC_URL subject = 'Message from benefit' if userId.isnumeric(): try: profile = Profiles.objects.get(userid=userId) contactMessage = render_to_string( templatePath + '/contact.html', { 'profileid': profile.id, 'userid': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.lastname, 'baseUrl': baseUrl, 'message': message }) toEmailId = settings.EMAIL_HOST_USER fromId = profile.userid.email sendStatus = sendmail(subject, contactMessage, toEmailId, fromId) if sendStatus == 'success': return json_response( { 'status': 'success', 'msg': 'Send successfully', 'sendStatus': sendStatus }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Mail send failed', 'sendmail': sendStatus }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User id' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User id' }, status=400)
def post(self, request, format=None): profileId = request.POST.get('profileId', None) if profileId.isnumeric(): try: profile = Profiles.objects.get(userid=profileId) subject = "User Report" admin_email_id = settings.EMAIL_HOST_USER fromId = profile.userid.email templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') message = render_to_string( templatePath + '/userreport.html', { 'profile_id': profile.id, 'user_id': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.firstname, 'email': profile.userid.email }) sendStatus = sendmail(subject, message, admin_email_id, fromId) if sendStatus == 'success': return json_response( { 'status': 'success', 'msg': 'Mail sent successfully', 'sendmail': sendStatus }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Mail sent failed', 'sendmail': sendStatus }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'success', 'msg': 'Invalid User' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User Id' }, status=200)
def post(self, request, format=None): email = request.POST.get('email', None) password = request.POST.get('password', None) fullName = request.POST.get('fullName', None) referalCode = request.POST.get('referalCode', None) loginType = request.POST.get('loginType', 'B') deviceId = request.POST.get('deviceId', None) deviceToken = request.POST.get('deviceToken', None) templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') if email is not None and password is not None and fullName is not None: token = ssoTokenGenerator(32) hashkey = ssoTokenGenerator(6) usercode = ssoTokenGenerator(6) try: user = Users.objects.get(email=request.POST['email']) return json_response( { 'status': 'error', 'msg': 'User already exists' }, status=status.HTTP_400_BAD_REQUEST) except Users.DoesNotExist: #referCode=fullName.replace(' ','')+ssoTokenGenerator(4) referCode = ssoTokenGenerator(6) subject = "User Registration Activation Email" #message="Email Verification Code: "+hashkey message = render_to_string( templatePath + '/email_verification.html', { 'hashkey': hashkey, 'email': email }) if referalCode: try: usercode = Profiles.objects.get( referalcode=referalCode) user = Users.objects.create( email=request.POST['email'], password=request.POST['password'], ssotoken=token, hash=hashkey, logintype=loginType, deviceid=deviceId, devicetoken=deviceToken, is_active=1, notification=1, usercode=usercode, isfirsttimelogin=0, createdate=settings.CURRENTDATE) try: userid = Users.objects.get( email=request.POST['email']) userp = Profiles.objects.create( userid=userid, firstname=fullName, referalcode=referCode, updatedate=settings.CURRENTDATE) try: userprofile = Profiles.objects.get( userid=userid.id) follower = Followings.objects.create( profileid=userprofile, followingprofileid=usercode, createdate=settings.CURRENTDATE) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid user id' }, status=status.HTTP_400_BAD_REQUEST) sendStatus = sendmail(subject, message, request.POST['email']) return json_response({ 'status': 'success', 'data': { 'token': token, 'email': user.email, 'id': userid.id, 'referCode': referCode, 'loginType': loginType }, 'msg': 'User sign up successfully.' }) except Users.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid email id' }, status=status.HTTP_400_BAD_REQUEST) except Profiles.DoesNotExist: return json_response({ 'status': 'error', 'msg': 'Invalid referral code' }) else: user = Users.objects.create( email=request.POST['email'], password=request.POST['password'], ssotoken=token, hash=hashkey, logintype=loginType, deviceid=deviceId, devicetoken=deviceToken, is_active=1, notification=1, usercode=usercode, isfirsttimelogin=0, createdate=settings.CURRENTDATE) try: userid = Users.objects.get(email=request.POST['email']) userp = Profiles.objects.create( userid=userid, firstname=fullName, referalcode=referCode, updatedate=settings.CURRENTDATE) sendStatus = sendmail(subject, message, request.POST['email']) return json_response({ 'status': 'success', 'data': { 'token': token, 'email': user.email, 'id': userid.id, 'referCode': referCode, 'loginType': loginType }, 'msg': 'User sign up successfully.' }) except Users.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid userid' }, status=status.HTTP_400_BAD_REQUEST) else: return json_response({ 'status': 'error', 'msg': 'Invalid Data' }, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): userId = request.POST.get('userId', None) productId = request.POST.get('productId', None) price = request.POST.get('price', None) shipping = request.POST.get('shipping', None) tax = request.POST.get('tax', None) transactionId = request.POST.get('transactionId', None) paymentStatus = request.POST.get('paymentStatus', None) platform = request.POST.get('platform', None) environment = request.POST.get('environment', None) paypalSdkVersion = request.POST.get('paypalSdkVersion', None) intent = request.POST.get('intent', None) paymentTime = request.POST.get('paymentTime', None) subject = 'Product Purchase' templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') if userId.isnumeric() and productId.isnumeric(): if price: isPrice = chekPrice(price) if isPrice == False: return json_response( { 'status': 'success', 'msg': 'Invalid Price,It should be number or decimal.' }, status=200) else: price = 0.00 if tax: isTax = chekPrice(tax) if isTax == False: return json_response( { 'status': 'success', 'msg': 'Invalid Tax,It should be number or decimal.' }, status=200) else: tax = 0.00 try: profile = Profiles.objects.get(userid=userId) try: product = Products.objects.get(id=productId) try: purchaseprd = Purchaseproduct.objects.get( transactionid=transactionId) return json_response( { 'error': 'error', 'msg': 'transactionId already exist' }, status=200) except Purchaseproduct.DoesNotExist: post = Purchaseproduct.objects.create( profileid=profile, productid=product, price=price, shipping=shipping, tax=tax, transactionid=transactionId, paymentstatus=paymentStatus, platform=platform, environment=environment, paypalsdkversion=paypalSdkVersion, intent=intent, paymenttime=paymentTime, createdate=settings.CURRENTDATE) # send notification to seller about product purchase sellerMessage = render_to_string( templatePath + '/product_seller_notification.html', { 'profileid': profile.id, 'userid': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.lastname }) toProductOwner = product.profileid.userid.email sendStatus = sendmail(subject, message, toProductOwner) # send notification to buyer about product purchase buyerMessage = render_to_string( templatePath + '/product_buyer_notification.html', { 'profileid': profile.id, 'userid': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.lastname }) toProductBuyer = profile.userid.email sendStatus = sendmail(subject, message, toProductBuyer) return json_response( { 'status': 'success', 'msg': 'Payment detail added successfully' }, status=200) except Products.DoesNotExist: return json_response( { 'error': 'error', 'msg': 'Invalid product id' }, status=200) except Profiles.DoesNotExist: return json_response( { 'error': 'error', 'msg': 'Invalid user id' }, status=200) else: return json_response( { 'status': 'error', 'msg': 'Invalid user id or product id' }, status=400)
def post(self, request, format=None): fromProfile = request.POST.get('fromProfile', None) toProfile = request.POST.get('toProfile', 'All') referalCode = request.POST.get('referalCode', None) subject = 'The Benefit app invite' templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') if fromProfile.isnumeric(): to_email_ids = [] to_list = '' if toProfile == 'All': try: profile = Profiles.objects.get(userid=fromProfile) message = render_to_string( templatePath + '/invite.html', { 'profileid': profile.id, 'userid': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.lastname }) try: userList = Users.objects.all() if userList: for uObj in userList: to_email_ids.append(uObj.email) sendStatus = sendmail(subject, message, to_email_ids, fromProfile, page='bulk') if sendStatus == 'success': return json_response( { 'status': 'success', 'msg': 'Send successfully' }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Mail send failed', 'sendmail': sendStatus }, status=200) except Users.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User id' }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User id' }, status=200) else: try: profile = Profiles.objects.get(userid=fromProfile) message = render_to_string( templatePath + '/invite.html', { 'profileid': profile.id, 'userid': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.lastname, 'referalcode': profile.userid.usercode }) if toProfile: toList = toProfile.split(',') else: toList = [] if message: try: userList = Users.objects.filter(id__in=toList) if userList: for uObj in userList: to_email_ids.append(uObj.email) sendStatus = sendmail(subject, message, to_email_ids, fromProfile, page='bulk') except Users.DoesNotExist: pass if sendStatus == 'success': return json_response( { 'status': 'success', 'msg': 'Send successfully', 'sendStatus': sendStatus }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Mail send failed', 'sendmail': sendStatus }, status=200) else: return json_response( { 'status': 'error', 'msg': 'Message cant be blank' }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User id' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User id' }, status=400)
def post(self, request, format=None): fromProfile = request.POST.get('fromProfile', None) toProfile = request.POST.get('toProfile', None) referalCode = request.POST.get('referalCode', None) subject = 'The Benefit app invite' templatePath = os.path.join(settings.BASE_DIR, 'templates/admin/email') baseUrl = settings.BASE_URL + settings.STATIC_URL if fromProfile.isnumeric(): try: profile = Profiles.objects.get(userid=fromProfile) message = render_to_string( templatePath + '/invite.html', { 'profileid': profile.id, 'userid': profile.userid.id, 'firstname': profile.firstname, 'lastname': profile.lastname, 'referalcode': profile.referalcode, 'baseUrl': baseUrl }) if message: if toProfile is not None: fromUserId = profile.userid.email sendStatus = sendmail(subject, message, toProfile, fromUserId) if sendStatus == 'success': return json_response( { 'status': 'success', 'msg': 'Send successfully', 'sendStatus': sendStatus }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Mail send failed', 'sendmail': sendStatus }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Recipient email id is required' }, status=200) else: return json_response( { 'status': 'error', 'msg': 'Message cant be blank' }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User id' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User id' }, status=400)