示例#1
0
文件: sendmail.py 项目: adoggie/swarm
def sendmail(request):
	cr = SuccCallReturn()
	try:
		conf = BaseAppServer.instance().getYamlConfig()['hippo']['smtp']

		mail_to =[]
		serial = SendMail_Serializer(data = request.data)
		if not serial.is_valid():
			print serial.errors
			return FailCallReturn(ErrorDefs.ParameterIllegal).httpResponse()

		mail_to = request.data['mail_to'].split(',')
		subject = request.data['subject']
		content = request.data['content']
		mail_from = request.data.get('mail_from')
		if not mail_from:
			mail_from = conf.get('mail_from')

		mail_host= conf.get('smtp_host')
		mail_port = conf.get('smtp_port')
		mail_user = conf.get("user")
		mail_user_password = conf.get('password')

		desert.network.sendmail.send_mail_smtp( mail_to, subject,content,mail_user,mail_user_password,mail_from,mail_host)
		identify = genUUID()
		cr.assign( identify )
	except:
		cr = FailCallReturn(ErrorDefs.ObjectNotExisted)
	return cr.httpResponse()
示例#2
0
def init_database():
	clearup()

	for user in def_sys_users:
		sys_user = X(user)
		print sys_user.user_name
		salt = 	genRandomString()
		password = getdigest(salt + sys_user.password)

		curTime = datetime.datetime.now()
		userObj = core.SystemUser(user_name = sys_user.user_name,
		                          user_type = sys_user.user_type,
		                          password = password,
		                          salt = salt,
		                          create_date = curTime,
		                          login_time = curTime,
		                          is_active = True
		                          )
		userObj.save()

	for key,app  in def_apps.items():
		app = X(app)
		core.Application(name=app.name,
		                 type=app.type,
		                 is_active=app.is_active,
		                 auth_uri=app.auth_uri,
		                 auth_param=app.auth_param).save()

	biz_models = []
	for model in def_models:
		model = X(model)
		apps = []
		dbo = core.AnalysisDataModel(name = model.name,type = model.type,comment=model.comment)
		dbo.save()
		for app_id in model.apps:
			app = core.Application.objects.get(type = app_id)
			dbo.apps.add(app)
		# print dbo.apps.all()
		biz_models.append(dbo)

	for client in def_clients:
		c = X(client)
		org = core.Orgnization(domain=c.domain,name=c.name,create_date=datetime.datetime.now(),
					employee = 1,phone='13916624477')
		org.save()

		# print client
		for user in c.users:
			print user.user_name
			salt = genRandomString()
			password = '******'
			password = getdigest( salt + password)
			user_obj = core.OrgUser(org= org,user_type=user.user_type,user_name=user.user_name,password=password,
				first_name= user.first_name,last_name=user.last_name,alias=u'',
				middle_name='mairo',position='sales manager',
				email=user.email,create_date = datetime.datetime.now(),
				is_active = True,login_time= datetime.datetime.now(),salt=salt
			)
			user_obj.save()
			for app in user.apps:
				app_type = core.Application.objects.get(type = app.type)
				app_obj = core.OrgUserAppConfig(app = app_type,user = user_obj,is_active = True,
					app_access_token=genUUID(),
					app_instance_url=u'http://sf.com/instance_url',
					app_user_id = u'2313123123124214',
					app_user_name = app.app_user_name,
					app_auth_time = datetime.datetime.now()
				)
				app_obj.save()

		for m in biz_models:
			org.data_models.add(m)
示例#3
0
文件: core.py 项目: adoggie/swarm
 def generateUniqueID(self, user='', factor=None):
     return genUUID()
示例#4
0
from django.contrib.auth.models import User

from model.core import models as core
from desert.misc import X,genUUID,getdigest
from koala.base import  PlatformType

USER_TYPE_ADMIN =1
USER_TYPE_NORMAL = 2

sf_auth_uri = 'https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=3MVG9ZL0ppGP5UrBaWfLJxKHPpqFQHGY1G4ViJZxYd.GypuWOEfF_.BiAGwhHNUk1mB_KuJGdyWLT5kJvOHuh&redirect_uri=http%3a%2f%2flocalhost%3a8001%2foauth&state=first'


def_apps = [
	{'app_id':'com.test.first_app','app_name':'first application for testing','access_id':'c121e7d470bb11e5ab90ac87a316f916','secret_key':'shahaiNg1y',
	 'devices':[
		 {'device_id':'f5d2211170bb11e5ab9dac87a316f916','account':'*****@*****.**','tag':'','access_token':getdigest(genUUID()),'platform':PlatformType.P_HTML5},
		 {'device_id':'7131251970bc11e5a52eac87a316f916','account':'*****@*****.**','tag':'','access_token':getdigest(genUUID()),'platform':PlatformType.P_HTML5},
		 {'device_id':'78fcfe6670bc11e5bc41ac87a316f916','account':'*****@*****.**','tag':'','access_token':getdigest(genUUID()),'platform':PlatformType.P_HTML5},
	 ]
	 },
]

def_users = [
	{'user_name':'scott','password':'******','email':'*****@*****.**',
	 'apps':[
		 {'app_id':'com.test.first_app','app_name':'first application for testing','access_id':'c121e7d470bb11e5ab90ac87a316f916','secret_key':'shahaiNg1y',
	 		'devices':[
		 		{'device_id':'dev_id_0001','account':'*****@*****.**','tag':'','access_token':'token_001','platform':PlatformType.P_HTML5},
		 		{'device_id':'dev_id_0002','account':'*****@*****.**','tag':'','access_token':'token_002','platform':PlatformType.P_HTML5},
		 		{'device_id':'dev_id_0003','account':'*****@*****.**','tag':'','access_token':'token_003','platform':PlatformType.P_HTML5},
	 		]
示例#5
0
	def form_valid(self, form):
		form.instance.create_time = datetime.datetime.now()
		form.instance.access_id = genUUID()
		form.instance.secret_key = random_password()
		form.instance.account = self.request.user.auth_user
		return super(ApplicationCreateView,self).form_valid(form)
示例#6
0
def create_device_access_token(**kwargs):
	return encodeBase64( genUUID() )