// Username is already in use by a different account.
return"","",status.Error(codes.AlreadyExists,"Username is already in use.")
}
logger.Error("Cannot find or create user with custom ID.",zap.Error(err),zap.String("customID",customID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Internal,"Error finding or creating user account.")
}
ifdbDisabledAt!=0{
logger.Debug("User account is disabled.",zap.String("customID",customID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Unauthenticated,"Error finding or creating user account.")
return"","",status.Error(codes.NotFound,"User account not found.")
}else{
logger.Error("Cannot find user with custom ID.",zap.Error(err),zap.String("customID",customID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Internal,"Error finding user account.")
}
}
ifdbDisabledAt!=0{
logger.Debug("User account is disabled.",zap.String("customID",customID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Unauthenticated,"Error finding or creating user account.")
returnstatus.Error(codes.AlreadyExists,"Username is already in use.")
}
logger.Error("Cannot find or create user with device ID.",zap.Error(err),zap.String("deviceID",deviceID),zap.String("username",username),zap.Bool("create",create))
returnstatus.Error(codes.Internal,"Error finding or creating user account.")
}
ifdbDisabledAt!=0{
logger.Debug("User account is disabled.",zap.String("deviceID",deviceID),zap.String("username",username),zap.Bool("create",create))
returnstatus.Error(codes.Unauthenticated,"Error finding or creating user account.")
}
query="INSERT INTO user_device (id, user_id) VALUES ($1, $2)"
returnstatus.Error(codes.Internal,"Error finding or creating user account.")
}
returnnil
})
iffnErr!=nil{
returndbUserID,dbUsername,fnErr
}
returndbUserID,dbUsername,nil
}else{
query:="SELECT user_id FROM user_device WHERE id = $1"
vardbUserIDstring
err:=db.QueryRow(query,deviceID).Scan(&dbUserID)
iferr!=nil{
iferr==sql.ErrNoRows{
// No user account found.
return"","",status.Error(codes.NotFound,"Device ID not found.")
}else{
logger.Error("Cannot find user with device ID.",zap.Error(err),zap.String("deviceID",deviceID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Internal,"Error finding user account.")
}
}
query="SELECT username, disabled_at FROM users WHERE id = $1"
logger.Error("Cannot find user with device ID.",zap.Error(err),zap.String("deviceID",deviceID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Internal,"Error finding user account.")
}
ifdbDisabledAt!=0{
logger.Debug("User account is disabled.",zap.String("deviceID",deviceID),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Unauthenticated,"Error finding or creating user account.")
// Username is already in use by a different account.
return"","",status.Error(codes.AlreadyExists,"Username is already in use.")
}
logger.Error("Cannot find or create user with email.",zap.Error(err),zap.String("email",email),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Internal,"Error finding or creating user account.")
}
ifdbDisabledAt!=0{
logger.Debug("User account is disabled.",zap.String("email",email),zap.String("username",username),zap.Bool("create",create))
return"","",status.Error(codes.Unauthenticated,"Error finding or creating user account.")