get current id of tenant - thingsboard platform - thingsboard

I'm trying to get the ID of the current tenant in thingthboard
I tried to look in their code where it is stored but I can not find
Anyone know?

I searched deep in the thingsboard code and finally found it:
initCurrentTenantId() {
this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.TENANT_ADMIN) {
this.CurrentTenantId = authUser.tenantId; }
})
).subscribe(res => {
console.log('**************userrrrrr:', res);
this.CurrentTenantId = res.tenantId;
});
}

Related

Oidc-client-js trigger login when app start.What is the correct way?

i am using identity server 4 and oidc-client-js for auth, with angular frame work. I faced it this issue,
I am trying to trigger login redirect when application start. First i tried this code;
this.authService.userManager.getUser().then((user) => {
if (!(user)) {
this.authService.userManager.signinRedirect();
}
});
and user always returning null. Then i tried the same code with timeout, like this;
this.authService.userManager.getUser().then((user) => {
setTimeout(() => {
if (!(user)) {
this.authService.userManager.signinRedirect();
}
}, 2000);
});
after that, everything works good. But i'm not comfortable about using timeout. I tried using subject in callback component signinRedirectCallback, i tried userLoaded event but i can't succeeded. And finally i wrote this code;
In app component ngOnInit;
if (!this.authService.currentUser) {
this.authService.userManager.signinRedirectCallback().then((user) => {
// this.authService.userLoadedSub.next(user);
this.authService.currentUser = user;
console.log("01");
//navigate related route
this.initData();
}).catch((err) => {
console.log("signinRedirectCallback Error", err);
this.authService.userManager.signinRedirect();
});
}
Is this a good way to what i need? Is there any other way?
Many thanks for yor helps.

How to make angular2 custom validators to run after we get the value

If I pass hard coded values in offerCheck validator it is working fine. But if I get values from api, null values is getting passed in paramets. Form is getting executed before we get the values from service. Please help me to make validate check after getting values from api.
this.newOffer = "aaa";
this.oldOffer = "aaa";
constructor(fb: FormBuilder) {
this.formGroup = fb.group({
'offer': [null, Validators.compose([Validators.required, this.offerCheck(newOfer, oldOffer)])],
})
offerCheck(new, old) {
return (control: FormControl) => {
if (new == old) {
return true;
}
}
}
What you want is probably the AsyncValidatorFn, here's a very simple example of how to create one:
export const OfferCheck: AsyncValidatorFn = (control: AbstractControl): Observable<boolean> => {
if (new == old) {
return Observable.of(this.http.get('/some-endpoint').first().map(res => res.data));
}
};
You don't provide enough information so this is just a guess on how you'd want it to be. But it should point you in the right decision.
An alternative method would be to use setValidators of the control(s) after you've fetched the data:
this.formGroup.get('offer').setValidators([Validators.required, this.offerCheck(newOfer, oldOffer)]);
I hope this helps.

react-native-fbsdk not returning email

I have integrated the react-native-fbsdk library and getting user profile info such as name, middle name etc except email
i have tried readPermissions={["email,"public_profile","friends"]}
Then too not getting email
Any help would be appreciated.
Thanks in advance
I'm facing the same issue and it looks like the only workaround is using the LoginManager class provided by react-native-fbsdk.
import {
LoginManager,
} from 'react-native-fbsdk';
const _fbLogin = () => {
LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
(result) => {
if (result.isCancelled) {
alert('Login cancelled');
} else {
alert('Login success with permissions: ' + JSON.stringify(result));
}
},
(error) => {
alert('Login fail with error: ' + error);
}
);
}
And you can try using that _fbLogin function as an event handler for a custom button. I did not find how to use it with the blue, out of the box facebook Log in button.
Hope it helps!
readPermissions has now been replaced with permissions
<LoginButton
permissions={["email", "user_friends", "public_profile"]}
onLoginFinished={this._onFacebookLoginFinished.bind(this)}
onLogoutFinished={this._onFacebookLogoutFinished.bind(this)}
/>
Once you've completed a login and have an access token, you need to use the Graph API https://github.com/facebook/react-native-fbsdk#graph-api to retrieve data
you can find explaination for it here

Request from Ember front to Rails back is not happening

I am implementing a front-end in ember 1.13 with a Rails back-end and having the following problem:
After the user is authenticated, I don't seem to be able to retrieve the user's record from the back-end. The browser debugger does not even show a request being made. This is code:
// app/services/session-user.js
import Ember from 'ember';
const { inject: { service }, RSVP } = Ember;
export default Ember.Service.extend({
session: service('session'),
store: service(),
loadCurrentUser() {
currentUser: {
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return this.get('store').findAll('user', userId);
}
}
}
});
There is a login controller which handles the authentication. But the code for getting the data is in the applications's route:
// app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
const { service } = Ember.inject;
export default Ember.Route.extend(ApplicationRouteMixin, {
sessionUser: service('session-user'),
beforeModel() {
if (this.session.isAuthenticated) {
return this._loadCurrentUser();
}
},
sessionAuthenticated() {
this._loadCurrentUser();
},
_loadCurrentUser() {
return this.get('sessionUser').loadCurrentUser();
},
});
For extra measure I am defining the session store:
// app/session-stores/application.js
import Adaptive from 'ember-simple-auth/session-stores/adaptive';
export default Adaptive.extend();
If there are files I should post, please let me know.
Any hints will be highly appreciated as I am rather new to ember. I have spent several hours researching without luck, as things seem to have changed quite a lot throughout versions.
Look at your service code.
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return this.get('store').findAll('user', userId);
}
I don't see code that you provided in question where you setting up user_id variable. So if user_id not defined then if statement won't get executed because of !.

Problem adding a dynamic field to a SPList in sharepoint

We have the following code in a webpart:
using (SPSite site = new SPSite("http://localhost/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.SiteUserInfoList;
if (!list.Fields.ContainsField("Office"))
{
list.Fields.Add("Office", SPFieldType.Text, false);
list.Update();
}
}
}
in the 4th line where we add a item to the list we get this error: "Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb".
Then we added this line before adding the item to the list:
web.AllowUnsafeUpdates = true;
Now we are getting this error:
"You are currently signed in as: [domain]\username".
Sign in as a different user.
The account that we are using have administrative access too.
Any idea how we can get the following code executing:
web.AllowUnsafeUpdates = true;
list.Fields.Add("Office", SPFieldType.Text, false);
list.Update();
Got it working the following way:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(web.Site.ID))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.SiteUserInfoList;
if (!list.Fields.ContainsField("Office"))
{
list.Fields.Add("Office", SPFieldType.Text, false);
list.Update();
}
}
}
});
Needed to run the codes with Full Control rights :)
But we shouldn't be writings all the cods this way.

Resources