I am very new to symfony and got knowledge in php. On my project my end result of db query is $user.\
if i use print_r($user) i get this result
xxx\xxxx\Article Object ( [username:xxxx\xxxx\Article:private] => asdfasdf [passsword:xxxx\xxxx\Article:private] => [usertype:xxxx\xxxx\Article:private] => gaeafsdfa)
how can i fetch the username to check against a specific user and if condition passes change password to other.
All i need to how to read the username and how to set the password.
I found the answer
I got to call as
$user->getUsername(); // to see the user name
$user->setPassword($generatedPassword); // to update the password.
Related
I am implementing an add ticket sale function
My db includes
User->uid->{name:abc,...., ticketSale:[{uidTicket: abcxyz, use: true //or false }]}
Ticket->uidTicket->{nameTicket: qwer, ......}
User will take the list Ticket(table Ticket) and add them into User's ArrayTicket
The problem is check uidTicket already exist in User's ArrayTicket?
The code below that i know:
firebase.firestore().collection("user").doc(Fire.shared.uid).update({ Ticket: firebase.firestore.FieldValue.arrayUnion(uid) }).then(() => {
alert('Get success')
});
this code is usefull if ArrayTicket is Array uid, it can check uidTicket is already exist then can add or not
but myProblem is ArrayObject and how can i check UID ticket inside User's arrayTicket?
I think you're looking for the array-contains filter, which allows you to check if the Ticket array contains a certain UID.
I want to create a new node in firebase realtime database when a field is created in an existing Firestore document.
I have been trying this:
exports.addUserCredentials = functions.firestore
.document(`Users/{UserID}/{username}`)
.onCreate((snapshot, context) => {
const newUserData = snapshot.data()
const newUserUsername = newUserData
const newUserUidDoc = context.params.UserID
return admin.database().ref(`/userCredentials/${newUserUsername}`).set({"UID": newUserUidDoc})
})
I have searched around the web I saw the path must be directed towards a document only and not a collection. BUT username in the path is a FIELD in the document.
I am getting this error while deploying and I have seen all similar questions but those didn't perfectly answered mine:
! functions: failed to update function addUserCredentials
HTTP Error: 400, The request has errors
The reason is can't change my path to Users/{UserID} which will make my code run perfectly is the fields of document are not added at once.
Here is screenshot of my firestore structure:
The 4 fields of document are updated in 2 batches.
The EMAIL and timeCreated fields are added first and those create the document.
While on the other hand, phoneData and username are fields are CREATED [not updated] after 5 seconds of Email and timeCreated.
So if I use onCreate() on the path Users/{UserID}, it will return UNDEFINED to my realtime database as the username field is ABSENT at that instant.
Is there any way to apply onCreate() on a specific field of the document?
[I am doing this to create a separate node which contains username and UID, this is to check if an username exists when a new user is trying to sign up]
So if the node is created with value undefined it will be an issue.
It will be like this:
The EMAIL and timeCreated fields are added first and those create the document. While on the other hand, phoneData and username are fields are CREATED [not updated] after 5 seconds of Email and timeCreated.
No matter what fields are adding once you created a document,it will be considered as an update operation against that document.As you mentioned in the question,there will be no field with field name called username with a document while you creating document.So it is not possible to get the value of username while you creating the document.
According to your explanation the field username will be only available with the onUpdate trigger.
So the code should be something like below
exports.addUserCredentials = functions.firestore
.document(`Users/{UserID}`)
.onUpdate((snapshot, context) => {
const beforeData = snapshot.before.data()
const afterData = snapshot.after.data()
if(!beforeData.username && afterData.username){
return admin.database().ref(`/userCredentials/${newUserUsername}`).set({"UID": newUserUidDoc})
}
})
I'm guessing you have to do something with re authing to remove the phone number because at the moment I am trying to do this:
const user = firebase.auth().currentUser;
user.updateProfile({phoneNumber: null}).then(() => { alert('success') }).catch(err => {alert(err)})
this is not working, but I am getting the success block
To remove a phone number account from a user, simply unlink it:
firebase.auth().currentUser.unlink(firebase.auth.PhoneAuthProvider.PROVIDER_ID);
As stated on the documentation:
You can update a user's basic profile information—the user's display
name and profile photo URL—with the updateProfile method.
This means you can only update the user's display name and profile photo. There's also the updateEmail method which can be used to update the user's email. But there's no way to update the phone.
In case anyone is looking for an answer to this question from an Admin SDK perspective, you just set the phoneNumber field on the UserRecord to null.
admin.auth().updateUser( user.uid, { phoneNumber: null } )
i am trying to save form state in database and want to view in a listing page with its error validation.
i.e, i want to validate a previously saved form state from my database.
this is a node type form .
i had already tried node_validate its not working because i fetch the data before submitting the node . so there is no nid and for that it is not working
and also tried drupal_validate_form but it is showing
[form_token] => The form has become outdated. Copy any unsaved work in the form below and then reload this page
EDIT
Any one with any help , "How to save a form inputs in data base and retrive it from database with out form submision.
Thank You In advance
Any help is most Appreciable.
If you look in Drupal Core, you see this in includes/form.inc at the drupal_validate_form function:
if (isset($form['#token'])) {
if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) {
$path = current_path();
$query = drupal_get_query_parameters();
$url = url($path, array('query' => $query));
// Setting this error will cause the form to fail validation.
form_set_error('form_token', t('The form has become outdated. Copy any unsaved work in the form below and then reload this page.', array('#link' => $url)));
// Stop here and don't run any further validation handlers, because they
// could invoke non-safe operations which opens the door for CSRF
// vulnerabilities.
$validated_forms[$form_id] = TRUE;
return;
}
}`
This shows that the "form has become outdated" message is being set here. So, you can make the isset($form[#token']) condition false by unsetting #token to prevent this message from appearing.
All you have to do is load the form state you're going to validate, and call
unset($form[#token']); before you call drupal_validate_form.
I am making asp.net mvc4 web application. I wrote contact form function in my controller which sends feedback from users. I am using System.Net.Mail class.
I am using Simplemembership and I extended UserProfile with string Email property.
How to get logged in user Email? I want to include it it sended message, so I Could answer.
I tried to use:
var em = from m in db.UserProfiles.Where(a => a.UserName.Contains(User.Identity.Name)) select m.Email;
string email = em.ToString();
but in the sent mail I have:
SELECT
[Extent1].[Email] AS [Email]
FROM [dbo].[UserProfile] AS [Extent1]
WHERE [Extent1].[UserName] LIKE #p__linq__0 ESCAPE N'~'
To retrieve a single entry of the database, you have to select the first row returned with the First() method:
string email = db.UserProfiles
.Where(a => a.UserName.Contains(User.Identity.Name))
.First().Email;
Hope it helps !
You already have the correct answer, so I am just throwing this up here for future searchers to see the shorter syntax.
string email = db.UserProfiles
.FirstOrDefault(a => a.UserName.Contains(User.Identity.Name)).Email;
However in your scenario, I would be concerned about User1 receiving emails intended for User11. To prevent this, you need to be more specific in your query
string email = db.UserProfiles
.FirstOrDefault(a => a.UserName == User.Identity.Name).Email;