const dbase=CONFIG("dbase");
const conURL=CONFIG("conURL");

const dbaseA=CONFIG("dbaseA");
const conURLA=CONFIG("conURLA");

var ObjectId = require('mongodb').ObjectID;
exports.install = function() {
	GROUP(['#contact'],function(){
	//----------------------------- recently added --------------------------------------------------------
		ROUTE('/new/user', view_newuser,['unauthorize']); 
	    ROUTE('/new/user',newINSuser,['post','upload','ajax','unauthorize']);
		
	});
	GROUP(['#user'],function(){
	  
	   	ROUTE('/user/insert',view_INSuser,['authorize','@administrator']); //--------- RECENTLY CHANGED
	    ROUTE('/user/insert',INSuser,['post','ajax','upload','authorize','@administrator']);   //--------- RECENTLY CHANGED
	    ROUTE('/user/update/{id}',view_UPDuser,['authorize','@administrator','@admin']); //--------- RECENTLY CHANGED    this is used for UPDuserinfo too
	    ROUTE('/user/update',UPDuser,['post','ajax','upload','authorize','@administrator']);   //--------- RECENTLY CHANGED

	    
	    ROUTE('/userinfo/insert/{id}',view_INSuserinfo,['authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    ROUTE('/userinfo/insert/{id}',INSuserinfo,['post','ajax','upload','authorize','@administrator','@admin']);   //--------- RECENTLY CHANGED
	    ROUTE('/userinfo/update/',UPDuserinfo,['post','ajax','upload','authorize','@administrator','@admin']);   //--------- RECENTLY CHANGED

	    // ROUTE('/useraddress/{id}',view_useraddress,['authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    // ROUTE('/useraddress/insert/{id}',INSuseraddress,['post','ajax','upload','authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    // ROUTE('/useraddress/update/{uid}',UPDuseraddress,['post','ajax','upload','authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    // ROUTE('/useraddress/delete/{uid}',DELuseraddress,['get','ajax','authorize','@administrator','@admin']); //--------- RECENTLY CHANGED


	    
        ROUTE('/user/list/{numpage}',view_userlist,['authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    ROUTE('user/list/filter',LSTusersFilter,['post','ajax','upload','authorize','@administrator','@admin']);  //--------- RECENTLY CHANGED
	    //ROUTE('user/view/pictuer/{id}',view_UserPic,['authorize','@administrator','@admin']);  //--------- RECENTLY CHANGED
    	//ROUTE('user/insert/pictuer',INSuserPic,['post','ajax','upload','authorize','@administrator','@admin',10000], 3084); //--------- RECENTLY CHANGED
	    //ROUTE('user/delete/pictuer',DELuserPic,['get','ajax','authorize','@administrator','@admin',10000], 3084);

	    ROUTE('/user/update/password',UPDuserPASS,['post','ajax','upload','authorize','@administrator']); //--------- RECENTLY CHANGED
        ROUTE('user/delete/',DELuser,['get','ajax','authorize','@administrator']); //--------- RECENTLY CHANGED
	    ROUTE('user/delete_force/',DELuser_force,['get','ajax','authorize','@administrator']); //--------- RECENTLY CHANGED
	    ROUTE('user/multidelete/',DELmultiuser,['post','ajax','upload','authorize','@administrator']); //--------- RECENTLY CHANGED

	    // ROUTE('/useraddress/',view_customeraddress,['authorize','@administrator','@admin','@user','@master','@student','@customer']); //--------- RECENTLY CHANGED
	    // ROUTE('/useraddress/insert/',INScustomeraddress,['post','ajax','upload','authorize','@administrator','@admin','@user','@master','@student','@customer']); //--------- RECENTLY CHANGED
	    // ROUTE('/useraddress/update/',UPDcustomeraddress,['post','ajax','upload','authorize','@administrator','@admin','@user','@master','@student','@customer']); //--------- RECENTLY CHANGED
	    // ROUTE('/useraddress/delete/',DELcustomeraddress,['get','ajax','authorize','@administrator','@admin','@user','@master','@student','@customer']); //--------- RECENTLY CHANGED

	    ROUTE('/user/change/password',view_customerPASS,['authorize','@administrator','@admin','@user']); //--------- RECENTLY CHANGED
	    ROUTE('/user/change/password',UPDcustomerPASS,['post','ajax','upload','authorize','@administrator','@admin','@user']); //--------- RECENTLY CHANGED

	    ROUTE('/user/update/',view_UPDcustomer,['authorize','@administrator','@admin','@user']); //--------- RECENTLY CHANGED   
	    ROUTE('/userinfo/insert/',INScustomerinfo,['post','ajax','upload','authorize','@administrator','@admin','@user']);   //--------- RECENTLY CHANGED
	    ROUTE('/user/updinfo/',UPDcustomerinfo,['post','ajax','upload','authorize','@administrator','@admin','@user']);   //--------- RECENTLY CHANGED

	    //ROUTE('/user/view/pictuer',view_CustomerPic,['authorize','@administrator','@admin','@user','@master','@student','@customer']);  //--------- RECENTLY CHANGED
    	//ROUTE('/user/insertPictuer',INScustomerPic,['post','ajax','upload','authorize','@administrator','@admin','@user','@master','@student','@customer',10000], 3084); //--------- RECENTLY CHANGED
	    //ROUTE('/user/deletePictuer',DELcustomerPic,['get','ajax','authorize','@administrator','@admin','@master','@student','@customer',10000], 3084);


	    //ROUTE('/usermedia/{id}',view_adminUsermedia,['authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    //ROUTE('/user/media/update/',UPDadminMedia,['get','ajax','authorize','@administrator','@admin']); //--------- RECENTLY CHANGED
	    //ROUTE('/usermedia/',view_customerusermedia,['authorize','@administrator','@admin','@user','@master','@student','@customer']); //--------- RECENTLY CHANGED
	    //ROUTE('/usermedia/update/',UPDcustomermedia,['get','ajax','authorize','@administrator','@admin','@user','@master','@student','@customer']); //--------- RECENTLY CHANGED


        //ROUTE('/user/',view_user,['authorize','@administrator','@admin','@user','@master','@student','@customer']);   //--------- RECENTLY CHANGED
        
        
        
	});

    // LOCALIZE('/components/*.html', ['compress']);

}


async function view_userlist(req,res) {
    var self=this;
    var model={address:"~../modules/https_modules/users/views/user_list",data:""};
  
    var partial=require(PATH.root('/modules/https_modules/users/user_view'));
	model.data=await partial.LSTusers(self,dbaseA);
    console.log(model.data.data);
    self.layout('layouts/admin');
    self.view('~../modules/https_modules/users/views/useradmin',model);
}

async function view_newuser(req,res) {
	var self=this;
	self.repository.user={role:"customer"};
  self.layout('layouts/layout');
  self.view('cpnewuser');
}
//----------ok
async function newINSuser(req,res){
	var result={};
	var self = this;
	self.status=200;
	console.log("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
	let body=self.req.body;
	console.log(body);
	var pass=body["phone"].slice(-6);
	const v=MODULE('https_modules/Hvalidation');
	if(v.FISphone(body["phone"]) && v.ISvalid(body["status"]) && v.ISvalid(body["name"]) && v.ISvalid(body["fam"]) && v.ISint(body["authCode"]) && (v.FISidcode(body["idcode"]) || self.user.role=="admin") && v.ISemail(body["idcode"])){
		const sms=MODULE('https_modules/Hsms');
		const pm=await sms.A_RcheckCode("0"+body["phone"],body["authCode"]);
		console.log(pm);
        if(pm.status==200 && pm.data){
    		var partial=require(PATH.root('/controllers/partial/users/user_ajax'));
    		result=await partial.INSuser(self,dbaseA,body);
        }else{
     		result["status"]=601;
			result['sms']="";
        }
	}else{
 		result["status"]=700;
		result['sms']="";
	}
	if(result['status']==203){
		result["sms"]="ثبت نام شما انجام شد.";
		if(self.user){
			result['status']=299;
		}else{
			await F.userloginATregister(self,dbase, result.data);
			if(self.repository.login){
				result["location"]="/new/melk";
				result["locationTXT"]="بخش سپردن ملک";
			}else{
				result["status"]=298;
			}
		}
	}
	if(result.status==203 || result.status==299 || result.status==298 || result.status==704){
	    result["sms"]
	    var pmU="نام کاربری : ";
	    var pmP="کلمه عبور : ";
		const sms=MODULE('https_modules/Hsms');
		console.log("111111112222222222233333333333");
		var st=sms.RSendMessage(CONFIG("ROnumber1"),["0"+body["phone"]],result.sms+"\n"+pmU+body["idcode"]+"\n"+pmP+pass+"\n"+CONFIG("sms_txt_D"),10);
		console.log(st);
		console.log("ddddddddddddddddddddddddddddddddddd");
	}
	result['data']=F.resource(result.status);
	self.json(result);
}
//----------ok
function view_INSuser(req,res){
	var self = this;
	self.repository.user=self.user;
	
	var model={address:"~../modules/https_modules/users/views/user_insert",data:""};
	self.status=200;
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);

}



function view_INSuserinfo(req,res){
	var self = this;
	self.repository.user=self.user;
	
	var model={address:"~../modules/https_modules/users/views/userinfo_insert",data:""};
	self.status=200;
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);

}


async function INSuserinfo(req,res){
    var result={};
	var self = this;
	self.status=200;
	var id=new ObjectId(self.params.id);
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.INSuserinfo(dbaseA,body,id);
	
    result['_id']=result.data;
 	result['data']=F.resource(result.status);

	self.json(result);

}



async function UPDuserinfo(req,res){
    var result={};
	var self = this;
	self.status=200;
    
	let body=self.req.body;
    var id=new ObjectId(body["userID"]);
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.UPDuserinfo(dbaseA,body,id);
	
    
 	result['data']=F.resource(result.status);

	self.json(result);
}




async function view_useraddress(req,res){
	var self = this;
	self.repository.user=self.user;
	
	var id=new ObjectId(self.params.id);
	
	var model={address:"~../modules/https_modules/users/views/useraddress",data:{data:"",provinces:""}};

	var partial=require(PATH.root('/modules/https_modules/users/user_view'));

	var q=await partial.useraddress(dbaseA,{_idu:id});
	
	model.data.data=q.data;
	model.data.provinces=q.provinces;
	console.log(model);
	console.log("-----------------------");
	//self.status=200;
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);

}



async function INSuseraddress(req,res){
    var result={};
	var self = this;
	self.status=200;
	var id=new ObjectId(self.params.id);
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.INSuseraddress(dbaseA,body,id);
	
    result['address']=result.data;
 	result['data']=F.resource(result.status);

	self.json(result);

}


async function UPDuseraddress(req,res){
    var result={};
	var self = this;
	self.status=200;
	var uid=new ObjectId(self.params.uid);
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
    
	result=await partial.UPDuseraddress(dbaseA,body,uid);
	
 	result['data']=F.resource(result.status);

	self.json(result);

}


async function DELuseraddress(req,res){
    var result={};
	var self = this;
	self.status=200;
	var uid=new ObjectId(self.params.uid);
	let query=self.req.query;
    var id=new ObjectId(query["id"]);
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
    console.log("--------"+id);
	result=await partial.DELuseraddress(dbaseA,id,uid);
	
 	result['data']=F.resource(result.status);

	self.json(result);

}

//----------ok

//----------ok
async function LSTusersFilter(req,res){
 	var self=this;
 	self.status=200;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.LSTusersFilter(self,dbaseA);
	if(result["status"]!=200){
	    result['data']=F.resource(result.status);
	}
	console.log(result);
	self.json(result);
}
//----------ok
async function view_UserPic(req,res){
	var self = this;
	
	self.repository.user=self.user;
	self.repository.admin=true;
	var model={address:"~../modules/https_modules/users/views/user_info",data:""};
	self.status=200;
	var id=new ObjectId(self.params.id);

	//if(((id*1)==1)&& (self.user._id!=1)){   // mainuser controll
	//	model["status"]=413;
	//}else{
		const mongo=MODULE('https_modules/HmongoDB');
		const con=await mongo.connfull(conURLA);
		if(con.status==200){
			var s=await mongo.join2merge(con.data,dbaseA,"user","_id","user-info","_id",{_id:id});
			if(self.user.role=="admin" && (s.data[0].role=="admin" || s.data[0].role=="administrator") && self.user._id!=s.data[0]._id){
                mongo.disconn(con.data);
                self.redirect("/api");
			}
			model.data=s.data[0];
			const file=MODULE('https_modules/Hfiles');
			var filename = PATH.public('images/users/user'+s.data[0]._id+"_1.jpg");
			var checkFile=await file.checkfile(filename);
			model.data['ax']=[];
			if(checkFile.data){
				model.data['ax']=["1"];
			}
		}else{
			model["status"]=500;
			
		}
		mongo.disconn(con.data);
	//}

	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);
}


async function view_CustomerPic(req,res){
	var self = this;
	self.repository.user=self.user;
	self.repository.admin=false;
	var model={address:"~../modules/https_modules/users/views/user_info",data:""};
	self.status=200;
	var id=new ObjectId(self.user._id);

	//if(((id*1)==1)&& (self.user._id!=1)){   // mainuser controll
	//	model["status"]=413;
	//}else{
		const mongo=MODULE('https_modules/HmongoDB');
		const con=await mongo.connfull(conURLA);
		if(con.status==200){
			var s=await mongo.join2merge(con.data,dbaseA,"user","_id","user-info","_id",{_id:id});
			model.data=s.data[0];
			const file=MODULE('https_modules/Hfiles');
			var filename = PATH.public('images/users/user'+s.data[0]._id+"_1.jpg");
			var checkFile=await file.checkfile(filename);
			model.data['ax']=[];
			if(checkFile.data){
				model.data['ax']=["1"];
			}
		}else{
			model["status"]=500;
			
		}
		mongo.disconn(con.data);
	//}

	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);
}
//----------ok
async function INSuserPic(req,res){
	var result={};
	var self = this;
	self.status=200;
	let body=self.req.body;
	let id=new ObjectId(body['id']);
	console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.INSuserpic(self,id);
	console.log(result);
	if(result.status!=200){result['data']=F.resource(result.status);}
	self.json(result);
}

async function INScustomerPic(req,res){
	var result={};
	var self = this;
	self.status=200;
	let id=new ObjectId(self.user._id);
	console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.INSuserpic(self,id);
	console.log(result);
	if(result.status!=200){result['data']=F.resource(result.status);}
	self.json(result);
}

//----------ok
async function DELuserPic(req,res){
	var result={};
	var self = this;
	self.status=200;
	let query=self.req.query;
	var id=new ObjectId(query['id']);
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.DELuserPic(self,dbase,id);
	result['data']=F.resource(result.status);
	self.json(result);
}


async function DELcustomerPic(req,res){
	var result={};
	var self = this;
	self.status=200;
	
	id=new ObjectId(self.user._id);
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.DELuserPic(self,dbase,id);
	result['data']=F.resource(result.status);
	self.json(result);
}

//----------ok
async function view_UPDuser(req,res){

	var self = this;
	self.repository.user=self.user;
	
	var id=new ObjectId(self.params.id);
	var model={address:"../modules/https_modules/users/views/user_update",data:""};
	var partial=require(PATH.root('/modules/https_modules/users/user_view'));

	var q=await partial.userinfo(self,dbaseA,id);
	model.data=q.data;
	console.log("-----------------------");
	console.log(model);
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);
}


//----------ok
async function INSuser(req,res){
	var result={};
	var self = this;
	self.status=200;
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.INSuser(self,dbaseA,body);
	
    result['_id']=result.data;
 	result['data']=F.resource(result.status);

	self.json(result);
}




async function UPDuser(req,res){
	var result={};
	var self = this;
	self.status=200;
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.UPDuser(self,dbaseA,body);
	

 	result['data']=F.resource(result.status);

	self.json(result);
}



//----------ok
async function UPDuserPASS(req,res){
	var result={};
	var self = this;
	var body=self.req.body;
	self.status=200;
	body["password"]=body["password"].replace(/\s/g, '');
	if(body['newpass'].length>5){
		if(body['newpass']==body['newpass2']){
		    var id=new ObjectId(body['userid']);
			var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
			result=await partial.UPDuserPASS(self,dbaseA,id);
			console.log(result);
		}else{
			result["status"]=709;
		}
	}else{
		result["status"]=707;
	}
    result["data"]=F.resource(result.status);
	
	self.json(result);
}
//----------ok
async function DELuser(req,res){
	var result={};
	var self = this;
	self.status=200;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.DELuser(self,dbaseA);
    result["data"]=F.resource(result.status);
	self.json(result);
}
//----------ok
async function DELuser_force(req,res){
	var result={};
	var self = this;
	self.status=200;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.DELuser_force(self,dbaseA);
    result["data"]=F.resource(result.status);
	self.json(result);
}



async function DELmultiuser(req,res){
	var result={};
	var self = this;
	self.status=200;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
	result=await partial.DELmultiuser(self,dbaseA);
    result["data"]=F.resource(result.status);
	self.json(result);
}


async function view_customeraddress(req,res){

	var self = this;
	self.repository.user=self.user;
	
	var id=new ObjectId(self.user._id);
	
	var model={address:"~../modules/https_modules/users/views/customeraddress",data:{data:"",provinces:""}};

	var partial=require(PATH.root('/modules/https_modules/users/user_view'));

	var q=await partial.useraddress(dbaseA,{_idu:id});
	
	model.data.data=q.data;
	model.data.provinces=q.provinces;
	console.log(model);
	console.log("-----------------------");
	//self.status=200;
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);

}
async function INScustomeraddress(req,res){
    var result={};
	var self = this;
	self.status=200;
	var id=new ObjectId(self.user._id);
	console.log(id);
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.INSuseraddress(dbaseA,body,id);
	
    result['address']=result.data;
 	result['data']=F.resource(result.status);
    
	self.json(result);

}



async function  UPDcustomeraddress(req,res){
    var result={};
	var self = this;
	self.status=200;
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
    var uid=new ObjectId(self.user._id);
	result=await partial.UPDuseraddress(dbaseA,body,uid);
	
 	result['data']=F.resource(result.status);

	self.json(result);

}

async function DELcustomeraddress(req,res){
    var result={};
	var self = this;
	self.status=200;
	let query=self.req.query;
    var id=new ObjectId(query["id"]);
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
    console.log("--------"+id);
    var uid=new ObjectId(self.user._id);
	result=await partial.DELuseraddress(dbaseA,id,uid);
	
 	result['data']=F.resource(result.status);

	self.json(result);

}


async function  UPDcustomerPASS(req,res){
	var result={};
	var self = this;
	var body=self.req.body;
	self.status=200;
	body['newpass']=body['newpass'].replace(/\s/g, ''); // حذف فاصله از اول و آخر متن
	body['newpass2']=body['newpass2'].replace(/\s/g, '');
	if(body['newpass'].length>5){
		if(body['newpass']==body['newpass2']){
		    var id=new ObjectId(self.user._id);
			var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
			result=await partial.UPDcustomerPASS(self,dbaseA,id);
			console.log(result);
		}else{
			result["status"]=709;
		}
	}else{
		result["status"]=707;
	}
    result["data"]=F.resource(result.status);
	
	self.json(result);
}




async function  view_customerPASS(req,res){
	var self = this;
	self.repository.user=self.user;
	var model={address:"~../modules/https_modules/users/views/changePass",data:""};
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);
}



async function  view_UPDcustomer(req,res){
	var self = this;
	self.repository.user=self.user;
	var id=new ObjectId(self.user._id);
	var model={address:"~../modules/https_modules/users/views/customer_update",data:""};
	var partial=require(PATH.root('/modules/https_modules/users/user_view'));
	var q=await partial.userinfo(self,dbaseA,id);
	model.data=q.data;
    console.log(model.data);
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);
}


async function INScustomerinfo(req,res){
    var result={};
	var self = this;
	self.status=200;
	var id=new ObjectId(self.user._id);
	let body=self.req.body;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.INSuserinfo(dbaseA,body,id);
	
    result['_id']=result.data;
 	result['data']=F.resource(result.status);

	self.json(result);
}

async function  UPDcustomerinfo(req,res){
    var result={};
	var self = this;
	self.status=200;

	let body=self.req.body;
    var id=new ObjectId(self.user._id);
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));

	result=await partial.UPDuserinfo(dbaseA,body,id);
	
 	result['data']=F.resource(result.status);

	self.json(result);
}



async function  view_adminUsermedia(req,res){
	var self = this;
	self.repository.user=self.user;
	var id=new ObjectId(self.params.id);
	var model={address:"~../modules/https_modules/users/views/usermedia",data:""};
	var partial=require(PATH.root('/modules/https_modules/users/user_view'));
	var q=await partial.usermedia(self,dbaseA,id); 
	model.data=q.data;
    console.log(model.data);
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);

}

async function  UPDadminMedia(req,res){
    var result={};
	var self = this;
	self.status=200;
	let query=self.req.query;
	if(query["id"]!=""){
		var uid=new ObjectId(query["id"]);
		console.log("----------------------------------");
		console.log(query["id"]);
		var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
		result=await partial.UPDusermedia(self,dbaseA,uid);	
	}else{
		result.status=700;
	}

 	result['data']=F.resource(result.status);
	self.json(result);

}



async function  view_customerusermedia(req,res){
	var self = this;
	self.repository.user=self.user;
	var id=new ObjectId(self.user._id);
	var model={address:"~../modules/https_modules/users/views/customermedia",data:""};
	var partial=require(PATH.root('/modules/https_modules/users/user_view'));
	var q=await partial.usermedia(self,dbaseA,id);
	model.data=q.data;
	self.layout('layouts/admin');
	self.view('~../modules/https_modules/users/views/useradmin',model);

}

async function  UPDcustomermedia(req,res){
    var result={};
	var self = this;
	self.status=200;
	var partial=require(PATH.root('/modules/https_modules/users/user_ajax'));
    var uid=new ObjectId(self.user._id);
	result=await partial.UPDusermedia(self,dbaseA,uid); // update user media base on user id
	
 	result['data']=F.resource(result.status);

	self.json(result);

}













