//#import $owl_orgs:services/modelService.jsx
//#import @include/checklogin.jsx
//#import $owl_website:services/modelService.jsx

function main(){
    var env = checklogin();
    if(!env){
        var ret = {
            state:'err',
            msg:'not login'
        }
        out.print(JSON.stringify(ret));
        return;
    }
    var uid = env.loginId;

    var params = JSON.parse($body);

    var id = params.id;
    var website = owl_websiteService.get(id);
    if(website.ownerId!==uid){
        var ret = {
            state:'err',
            msg:'no permission'
        }
        out.print(JSON.stringify(ret));
        return;
    }
    website.siteName = params.siteName;
    website.phone = params.phone;
    website.email = params.email;
    website.description = params.description;

    owl_websiteService.update(website);
    var ret = {
        state: 'ok'
    }
    out.print(JSON.stringify(ret));
    return;
}

main();