I'm using Postgres,prisma,nextauth.
try to get twitter username(screen_name)
this is my schema.prisma.
model User {
id String #id #default(cuid())
name String?
screenname String #unique
screen_name String #unique
username String #unique
email String? #unique
password String?
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
}
Argument username for data.screenname is missing.\n' +
Argument username for data.username is missing.\n' +
Argument username for data.screen_name is missing.\n' +
Related
Is there a way to set a constructor optional param?
I mean something like:
User.fromData(this._name,
this._email,
this._token,
this._refreshToken,
this._createdAt,
this._expiresAt,
this._isValid,
{this.id});
It indicates that
Named option parameters can't start with an underscore.
But I need this field as private, so, I'm lost now.
This is a more general answer for future viewers.
Positional optional parameters
Wrap the optional parameter with [ ] square brackets.
class User {
String name;
int age;
String home;
User(this.name, this.age, [this.home = 'Earth']);
}
User user1 = User('Bob', 34);
User user2 = User('Bob', 34, 'Mars');
Optional parameters need to be nullable if you don't provide a default value:
class User {
String name;
int age;
String? home; // <-- Nullable
User(this.name, this.age, [this.home]);
}
Named optional parameters
Wrap the optional parameter with { } curly braces.
class User {
String name;
int age;
String home;
User(this.name, this.age, {this.home = 'Earth'});
}
User user1 = User('Bob', 34);
User user2 = User('Bob', 34, home: 'Mars');
The default for home is "Earth", but like before, if you don't provide a default then you need to change String home to String? home.
Private fields
If you need private fields then you can use [] square brackets:
class User {
int? _id;
User([this._id]);
}
User user = User(3);
or do as the accepted answer says and use an initializer list:
class User {
int? _id;
User({int? id})
: _id = id;
}
User user = User(id: 3);
Named required parameters
Named parameters are optional by default, but if you want to make them required, then you can use the required keyword:
class User {
final String name;
final int age;
final String home;
User({
required this.name,
required this.age,
this.home = 'Earth',
});
}
User user1 = User(name: 'Bob', age: 34);
User user2 = User(name: 'Bob', age: 34, home: 'Mars');
You need to use a simple parameter and initialize your private field in initializer list.
class User {
final String _id;
final String _name;
User.fromData(this._name, {required String id})
: _id = id;
}
In addition to great Suragch's answer I wanted to mention required word. You can use it for multiple constructor or function named parameters to specify required ones.
class User {
int _id;
String _firstName;
String _lastName;
User({required int id, String firstName = "", String lastName})
: _id = id, // required parameter
_firstName = firstName, // optional parameter with default value ""
_lastName = lastName; // optional parameter without default value
}
User user1 = User(id: 1);
User user2 = User(id: 2, firstName: "John");
User user3 = User(id: 3, lastName: "Snow");
Related Dart docs here.
For Dart version <= 2.10 #required is an annotation and used with the # prefix.
i have a user that i give a role to it, and i want when i create the user, to show the roles in a dropdown, then i can select the role that i want to give to him, how can i do it ?? please i really need help in it, cause im new in grails here is the user.groovy
class User {
transient securiteService
String username
String password
String nom
String prenom
String email
String tel
static hasMany = [roles : Role]
static constraints = {
username blank: false, unique: true
password blank: false,display: false
nom nullable: true
prenom nullable: true
email email:true, nullable:true
tel nullable:true, maxSize:20, matches:/[\+]{0,1}[0-9\s]{3,15}/
}
static mapping = {
password column: '`password`'
sort nom: "asc"
affectations sort : "dateAffectation", order:"desc"
intervention sort : "responsable", order:"desc"
}
}
The following example will help you, make necessary changes in your code according to your need.
For example you have a table / domain Role
class Role {
String roleId
String roleName // e.g ROLE_ADMIN
}
// Populate the dropdown in your GSP view ( this will populate all the roles present in the Role table)
<g:select from="${Role.list().roleName}" name="selectUserRole"
optionKey=""
optionValue=""/>
I have an MVC 5 application with .NET Identity 2.0. I need to migrate users from the clients legacy database. I am going to use an INSERT statement to insert them into the SQL Server tables (ASPNetUsers, ASPNetUserROles etc).
The problem is I want to insert a temporary password (firstname+lastname). Then I will separately send them an email and ask them to log in and change the password on the first log in.
How do I insert a hashed password (based on firstname+lastname) through a SQL Insert statement into the table?
Thanks,
Sanjeev
Wrote the following code. It seems to work. The first part uses the UserManager methods and the second part inserts the person into my own db tables.
Please comment if this is the right approach!
public ActionResult Seed()
{
string lastname;
string firstname;
string email;
string password;
lastname = "LastNAme";
firstname = "FirstName";
email = "Email#gmail.com";
password = "TempPassword";
var user = new ApplicationUser { UserName = email, Email = email };
var result = UserManager.Create(user, password);
UserManager.AddToRole(user.Id, "User");
var person = new Person()
{
UserName = user.UserName,
UserId = user.Id,
LastName = lastname,
FirstName = firstname,
Email = email
};
db.People.Add(person);
db.SaveChanges();
}
I get the following error when I try to save a domain class, in grails:
No signature of method: java.lang.String.save() is applicable for argument types: () values: []
Possible solutions: size(), size(), take(int), wait(), any(), wait(long). Stacktrace follows:
I have a service that pareses an XML string into domain objects. I then try to save the domain and get that error. I've debugged and know that all the data is valid. Here is my code:
def newProfile="";
newProfile = new LinkedinProfile(
firstName : "${linkedinProfileFeed.'first-name'}",
lastName : "${linkedinProfileFeed.'last-name'}",
dobYear : "${linkedinProfileFeed.'date-of-birth'.'year'}",
dobMonth : "${linkedinProfileFeed.'date-of-birth'.'month'}",
dobDay : "${linkedinProfileFeed.'date-of-birth'.'day'}" ,
imgUrl : "${linkedinProfileFeed.'picture-url'}",
siteStandardAddress : "${linkedinProfileFeed.'site-standard-profile-request'}",
oAuthToken : accessTokenKey.toString(),
secretKey : accessTokenSecret.toString()
)
.id="${linkedinProfileFeed.id}".toString()
log.debug("${linkedinProfileFeed.id}".toString())
log.debug("${linkedinProfileFeed.'first-name'}")
log.debug("${linkedinProfileFeed.'last-name'}")
log.debug("${linkedinProfileFeed.'date-of-birth'.'year'}")
log.debug("${linkedinProfileFeed.'date-of-birth'.'month'}")
log.debug("${linkedinProfileFeed.'date-of-birth'.'day'}")
log.debug("${linkedinProfileFeed.'picture-url'}")
log.debug("${linkedinProfileFeed.'site-standard-profile-request'}")
log.debug(accessTokenKey.toString())
log.debug(accessTokenSecret.toString())
log.debug("end debug")
newProfile.save();
Also, I'm not to familiar with grails and springsource, but in .Net, I can access an objects properties using the dot operator. For example, if I had an object as described above, I could just type newProfile. and would have access to all the properties. In grails this doesnt happen. is this by design or an error in my code?
below is my domain class, as well.
class LinkedinProfile {
String firstName
String lastName
String dobYear
String dobMonth
String dobDay
String oAuthToken
String secretKey
String id
String imgUrl
String siteStandardAddress
Date dateCreated
Date lastUpdated
long version
static hasMany = [
linkedinLocation : LinkedinLocation,
linkedinSkill : LinkedinSkill
]
static mapping = {
cache true
id generator: 'assigned'
columns {
firstName type:'text'
lastName type:'text'
oAuthToken type:'text'
secretKey type:'text'
dobYear type:'text'
dobMonth type:'text'
dobDay type:'text'
imgUrl type:'text'
siteStandardAddress type:'text'
}
}
static constraints = {
firstName (nullable:true)
lastName (nullable:true)
oAuthToken (nullable:false)
secretKey (nullable:false)
dobYear (nullable:true)
dobMonth (nullable:true)
dobDay (nullable:true)
id (nullable:false)
imgUrl (nullable:true)
siteStandardAddress (nullable:true)
}
def beforeInsert = {
//to do: before insert, capture current email that is stored in the db
}
def afterInsert={
//resave email
}
}
The error indicates you are calling save() on a String. If we investigate, we see that you are. This is because you are assigning
newProfile = new LinkedinProfile().id="${linkedinProfileFeed.id}".toString()
and so newProfile is actually the String linkedinProfileFeed.id, not a new LinkedinProfile() as one might expect.
Compare
groovy> def foo = new Post().id="1"
groovy> foo.class
Result: class java.lang.String
with
groovy> def foo = new Post(id: "1")
groovy> foo.class
Result: class test.Post
You probably want to put the id into the constructor arguments. Regardless, you need newProfile to end up as a LinkedinProfile instance. Then you can call save() on it.
Also yes, you can use the dot operator in Groovy.
I have a Groovy class like so:
class Person {
String firstName
String lastName
Status status = StatusEnum.ACTIVE
}
And I'm creating an instance of it with an object initializer:
def person = new Person(
firstName: "Bob", lastName: "Yelo", status: StatusEnum.INACTIVE)
However, this doesn't modify the person's status and it remains as ACTIVE. I have to explicitly declare it:
person.status = StatusEnum.INACTIVE
Which properly sets the status. Does anyone know why I have to explicitly set it?
I'm guessing it's having something to do with the type of the field being Status rather than StatusEnum?
Declaring it like this worked as you're suggesting it should groovy console:
enum StatusEnum {
ACTIVE, INACTIVE
}
class Person {
String firstName
String lastName
StatusEnum status = StatusEnum.ACTIVE
}
def person = new Person(firstName: "Bob", lastName: "Yelo", status: StatusEnum.INACTIVE)
assert StatusEnum.INACTIVE == person.status