thingsboard邮箱自动激活功能

thingsboard激活主要是靠user_credentials表中“enabled ”字段和“activate_token”字段,所以说我们在数据插入的时候更新一下这个字段就可以实现自动激活功能了

第一步:创建函数user_credentials_insert_trigger_fun()


CREATE OR REPLACE FUNCTION user_credentials_insert_trigger_fun()
returns trigger as $$
begin
    UPDATE "public"."user_credentials" set enabled = 't' , activate_token = null where id = new.id;
    return new;
end;
$$
language plpgsql;


第二步:创建postgreSQL触发器,当数据插入后会执行 user_credentials_insert_trigger_fun()函数更新此数据的“enabled ”和“activate_token”字段

CREATE TRIGGER insert_user_credentials_trigger
after insert on "public"."user_credentials"
for each row execute procedure user_credentials_insert_trigger_fun();

其他

1.查看触发器语法

SELECT * FROM pg_trigger

2.删除触发器

drop trigger ${trigger_name} on ${table_of_trigger_dependent};

 3.修改函数“CREATE OR REPLACE”创建或修改

CREATE OR REPLACE FUNCTION update_user_credentials_fun()
returns trigger as $$
begin
    UPDATE "public"."user_credentials" set enabled = 't' ,PASSWORD='$2a$10$ciDR1USkB986q661s5wKL.35wWdeOMAEBdGlEqFEu02tr/DyNFaCC', activate_token = null where id = new.id;
    return new;
end;
$$
language plpgsql;

 

你可能感兴趣的:(thingboard)