Is it possible to generate temporary URL or route using angular and ui-router? - angularjs

As the question title says, is it possible to generate a temporary URL using ui-router that routes to a view which displays data of a patient without showing patient ids or any identifying information in the URL? The link should be generated when a button is clicked. In other words, a url with random characters like www.example.com/xuye9039j23l. Once this URL is viewed and processed (say save button is clicked, then the URL can't be used again). Can someone give me a logic on how this can be made possible? I guess it would be somewhat similar to password recovery email in which the link expires once it's clicked. I'm using C# Web API if it is important.

I believe this might be the answer you are looking for: Angular ui router passing data between states without URL
However, I would consider a different strategy if you would like more granularity in control of the accessibility of this report.
Assuming you have a database to work with, perhaps you could create a new database table which might contain the following:
The ID of the user
A temporary generated token which will be used for routing to your patient details page
Perhaps a expiration date/time.
have your button call an API endpoint on your web server which might do the following:
Given a users ID and some subset of information, generate a hash of the information (include the ID of the current column as this will ensure uniqueness of the hash for multiple links generated for the same user). This will be the token.
Store the hash in your new database table with an expiration date/time.
Respond to the web request with the hash/token so you can route to the client details page with the token.
Then, when the user is redirected to the client details page, you can use your back-end (web server) to check for expiration or any other limiting factors you wish to put in place for the accessibility of this page.
Just my thoughts on the matter.

Yes this is possible. It has more to do with your backend code then javascript.
In essence you will need to have a server validate your id, and if it is valid display message. If it is not valid return 400 or something and tell them they have an invalid id. You will need to persist the Id to a datastore with some sort of time/use column saying if it is valid or not.
I will give a WebAPI example.
app.controller('myCtrl', function($scope,$stateParams,patientService) {
if($stateParams.id != undefined)
{
patientService.Get($stateParams.id).then(function(success){
$scope.Data = success;
},
function(error)
{
//redirect or display cannot use this url message
}
});
}
WebAPI
public HttpResponseMessage Get(string id)
{
//use business logic to validate ID
//if Id is valid return cool data
if (isValid(id))
{
return request.CreateResponse(HttpStatusCode.OK,data);
}
return request.CreateResponse(HttpStatusCode.BadRequest);
}

Related

Get page URL for scheduled publishing

My editors want to know the end page url for publishing in social media.
Is there any way to get the page URL as when it will be published before actually publishing it (scheduled publishing)?
slug_url should give you what you need:
https://docs.wagtail.org/en/latest/topics/writing_templates.html?highlight=slugurl#slugurl-tag
Note that slugurl might provide a relative link, so if it does, then you would have to prepend the domain name to the relative url in order to create the final url for the user. See the test_slugurl_tag() routine in the tests for an example of how to use slugurl in Python code.
Note also that if the location of the page in the page tree is changed or the slug (as defined in the Promote tab) is changed, then the url that you retrieved with slugurl prior to any such change will no longer be valid. However, if you are using Wagtail 2.16+, then this problem can be handled automatically if you use the wagtail.contrib.redirects app.
Here a code snippet that takes in account when the slug changes or the page is moved in the tree (you will need to subclass the Page model somehow and add a new field published_url):
def save_revision(self, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True,
log_action=False, previous_revision=None, clean=True):
old_record = Page.objects.get(id=self.id)
if old_record.slug != self.slug:
kwargs = {'update_fields': ['slug']}
Page.save(self, kwargs)
self.published_url = self.get_full_url()
return Page.save_revision(self, user, submitted_for_moderation, approved_go_live_at, changed,
log_action, previous_revision, clean)

Different views for different users in reactJS

I am having a problem in ReactJS. I want to create a text editor ( with ReactQuill). So, I want different accounts for each user, such that, if one person creates a note and edits it in his account, the other person should not see this.for example this is my current stage - https://wright-text.web.app. After you create your account and login you would see a note called first note because that's the note I created. What should I do so that when you login you see no notes because you have not created a note, but when I login, I should see the note I had already created. How would I do this ??
You need to add a scope to notes endpoint so that user could only GET notes, which they have created.
You need to add query parameters in the API you are fetching. For example, if you are fetching data via a GET request, add in some specific user id that you assign to your user upon validation and then fetch data of a particular user using that id as a query parameter on your API.

how to do terms and agreement show only once for one user?

I have a login page,
when a user login for the first time it should show the terms and agreement popup with accept button.
if user is accepted it for the first time . when user login for next time popup should not come.
i want to use local storage for this function no db changes allowed.
so what i have to save in localstorage. the scenario is complex when this has to work for diffrent users.
in angularjs i m using ngstorage plugin.
i can save data into local storage like
$localStorage.data="username";
in this case how i have to save for diffrent diffrent user?
You can have a key value pair, where key indicates the username and value indicate whether it has been loaded or not and push them into an array.
Something like this,
var testObj = { 'John': true };
// Put the object into storage
localStorage.setItem('John', JSON.stringify(testObject));
Similarly for all the users.
Then retrieved by using username,
var retrievedObject = localStorage.getItem('John');
console.log('User has already loaded: ', JSON.parse(John));
DEMO APP USING angular-local-storage

Get the some data after redirecting to another page

I get data form a Web services : I just specify two dates (start date , stop date )in the "localhost:3000/Person" and i have a method that return all objects between this dates in a table with a column called "Details" , this link show us the details of this object "localhost:3000/Person"/Details/:id .
So I want that when I return to the "localhost:3000/Person" page I find the some data between the two dates that the user has specified , how can I proceed ???
I guess you are asking how you can save the search parameters entered by your user on the front-end side (angularjs)?
You can create a service to store those values. Services are singleton and they persist if you don't reload your app.
Store the start and stop date in this service and when reloading your main page check in you have a value store in it.
Edit:
As said by #Adrian Faciu in the comment you should use the service to access your start and stop date directly.

Understanding Firebase User Auth

I made a simple Angular + Firebase app, which you can see here.
I want to add user authentication to it using Firebase, and have successfully been able to create an account and login using Firebase's email and password auth.
The problem is, I don't know how to take the next step to separate each user's data — I want each user to only to be able to change their own data, and show nothing until they're logged in.
The only thing I could think of was to change the firebase URL I'm using to separate the FirebaseArrays I'm using, but that seems super hacky and didn't work when I tried it.
How am I supposed to use the unique uids to create separate, individual user data?
So every user will have a unique id within the authorize table , of which you cannot directly access ( in that you cannot add tables - firebase keeps it locked down for security reasons )
This still allows for a separation based on the id. There will essentially be a books array, You could add an array of users on each book, but that could get redundant. I think the best solution would be to create a user_books array. This will list all the users by id that have books, with the bookID as a nested array
user_books
-Jsdee23dnn23d2n3d
|- sdfEDASED82342dsd : true
|- SDEdsdfwer343dsdf : true
-Jsdeesdfffffs433
|- 43334sdfsrfesrdfg : true
|- sdfsf333fsdfsrrrr : true
This connects the books to the users. So each user has an array of books . This is the target to access when you want the user to perform CRUD operations
var usersRef = new Firebase('https://test.firebaseio-demo.com/user_books');
var ref = usersRef.child('userID');
When you create a book you will need to update both the book table and the user_books table with the selected user(s) associated to the book

Resources