本文整理汇总了Java中com.google.appengine.api.users.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
User类属于com.google.appengine.api.users包,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTestSms
import com.google.appengine.api.users.User; //导入依赖的package包/类
@ApiMethod(
name = "sendTestSms",
path = "sendTestSms",
httpMethod = ApiMethod.HttpMethod.POST
)
@SuppressWarnings("unused")
public StringWrapperObject sendTestSms(
// final HttpServletRequest httpServletRequest,
final User googleUser,
final @Named("phoneNumber") String phoneNumber,
final @Named("smsMessage") String smsMessage
// see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
) throws UnauthorizedException, BadRequestException, NotFoundException, NumberParseException,
IllegalArgumentException, TwilioRestException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);
/* --- Send SMS */
Message message = TwilioUtils.sendSms(phoneNumber, smsMessage);
return new StringWrapperObject(message.toJSON());
}
示例2: CryptonomicaUser
import com.google.appengine.api.users.User; //导入依赖的package包/类
public CryptonomicaUser(User googleUser,
PGPPublicKeyData pgpPublicKeyData,
NewUserRegistrationForm newUserRegistrationForm) {
this.userId = googleUser.getUserId();
this.webSafeStringKey = Key.create(
CryptonomicaUser.class, googleUser.getUserId()
).toWebSafeString();
this.firstName = pgpPublicKeyData.getFirstName().toLowerCase();
this.lastName = pgpPublicKeyData.getLastName().toLowerCase();
this.birthday = newUserRegistrationForm.getBirthday();
this.googleUser = googleUser;
if (googleUser.getEmail() != null) {
this.email = new Email(googleUser.getEmail().toLowerCase()); // or email = pgpPublicKeyData.getUserEmail()
}
if (newUserRegistrationForm.getUserInfo() != null) {
this.userInfo = new Text(newUserRegistrationForm.getUserInfo());
}
this.publicKeys = new ArrayList<>();
Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
this.publicKeys.add(
Key.create(
cryptonomicaUserKey, PGPPublicKeyData.class, pgpPublicKeyData.getFingerprint()
)
);
}
示例3: ensureCryptonomicaRegisteredUser
import com.google.appengine.api.users.User; //导入依赖的package包/类
public static CryptonomicaUser ensureCryptonomicaRegisteredUser(final User googleUser)
throws UnauthorizedException {
ensureGoogleAuth(googleUser);
CryptonomicaUser cryptonomicaUser = null;
try {
cryptonomicaUser = ofy()
.load()
.key(Key.create(CryptonomicaUser.class, googleUser.getUserId()))
.now();
} catch (Exception e) {
LOG.warning(e.getMessage());
}
if (cryptonomicaUser == null) {
throw new UnauthorizedException("You are not registered on Cryptonomica server");
}
return cryptonomicaUser;
}
示例4: ensureNotaryOrCryptonomicaOfficer
import com.google.appengine.api.users.User; //导入依赖的package包/类
public static CryptonomicaUser ensureNotaryOrCryptonomicaOfficer(final User googleUser)
throws UnauthorizedException {
//
CryptonomicaUser cryptonomicaUser = ensureCryptonomicaRegisteredUser(googleUser);
//
LOG.warning("cryptonomicaUser: ");
LOG.warning(new Gson().toJson(cryptonomicaUser));
// if (cryptonomicaOfficer == null && notary == null) {
LOG.warning("cryptonomicaUser.getCryptonomicaOfficer(): " + cryptonomicaUser.getCryptonomicaOfficer());
LOG.warning("cryptonomicaUser.getNotary(): " + cryptonomicaUser.getNotary());
// if isCryptonomicaOfficer and isNotary are both false or null:
if ((cryptonomicaUser.getCryptonomicaOfficer() == null || !cryptonomicaUser.getCryptonomicaOfficer())
&& (cryptonomicaUser.getNotary() == null || !cryptonomicaUser.getNotary())) {
throw new UnauthorizedException("You are not a Notary or Cryptonomica officer");
}
return cryptonomicaUser;
}
示例5: newSharedProduct
import com.google.appengine.api.users.User; //导入依赖的package包/类
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newSharedProduct(@FormParam("productID") String productID,
@FormParam("productName") String productName,
@Context HttpServletResponse servletResponse) throws Exception {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return;
}
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Entity entity = new Entity("SharedList", productID);
entity.setProperty("email", user.getEmail());
entity.setProperty("productName", productName);
entity.setProperty("sharedDate", new Date());
datastore.put(entity);
servletResponse.getWriter().println(productName + " has been added.");
servletResponse.flushBuffer();
}
示例6: convertEmailAddressToGaeUserId
import com.google.appengine.api.users.User; //导入依赖的package包/类
/**
* Converts an email address to a GAE user id.
*
* @return Numeric GAE user id (in String form), or null if email address has no GAE id
*/
public static String convertEmailAddressToGaeUserId(String emailAddress) {
final GaeUserIdConverter gaeUserIdConverter = new GaeUserIdConverter();
gaeUserIdConverter.id = allocateId();
gaeUserIdConverter.user =
new User(emailAddress, Splitter.on('@').splitToList(emailAddress).get(1));
try {
// Perform these operations in a transactionless context to avoid enlisting in some outer
// transaction (if any).
ofy().doTransactionless(() -> ofy().saveWithoutBackup().entity(gaeUserIdConverter).now());
// The read must be done in its own transaction to avoid reading from the session cache.
return ofy()
.transactNew(() -> ofy().load().entity(gaeUserIdConverter).safe().user.getUserId());
} finally {
ofy().doTransactionless(() -> ofy().deleteWithoutBackup().entity(gaeUserIdConverter).now());
}
}
示例7: doGet
import com.google.appengine.api.users.User; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
UserService userService = UserServiceFactory.getUserService();
if (userService.isUserLoggedIn()) {
// Save the relevant profile info and store it in the session.
User user = userService.getCurrentUser();
req.getSession().setAttribute("userEmail", user.getEmail());
req.getSession().setAttribute("userId", user.getUserId());
String destination = (String) req.getSession().getAttribute("loginDestination");
if (destination == null) {
destination = "/books";
}
resp.sendRedirect(destination);
} else {
resp.sendRedirect(userService.createLoginURL("/login"));
}
}
示例8: createDocument
import com.google.appengine.api.users.User; //导入依赖的package包/类
/**
* Code snippet for creating a Document.
* @return Document Created document.
*/
public Document createDocument() {
// [START create_document]
User currentUser = UserServiceFactory.getUserService().getCurrentUser();
String userEmail = currentUser == null ? "" : currentUser.getEmail();
String userDomain = currentUser == null ? "" : currentUser.getAuthDomain();
String myDocId = "PA6-5000";
Document doc = Document.newBuilder()
// Setting the document identifer is optional.
// If omitted, the search service will create an identifier.
.setId(myDocId)
.addField(Field.newBuilder().setName("content").setText("the rain in spain"))
.addField(Field.newBuilder().setName("email").setText(userEmail))
.addField(Field.newBuilder().setName("domain").setAtom(userDomain))
.addField(Field.newBuilder().setName("published").setDate(new Date()))
.build();
// [END create_document]
return doc;
}
示例9: doPost
import com.google.appengine.api.users.User; //导入依赖的package包/类
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Greeting greeting;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); // Find out who the user is.
String guestbookName = req.getParameter("guestbookName");
String content = req.getParameter("content");
if (user != null) {
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail());
} else {
greeting = new Greeting(guestbookName, content);
}
// Use Objectify to save the greeting and now() is used to make the call synchronously as we
// will immediately get a new page using redirect and we want the data to be present.
ObjectifyService.ofy().save().entity(greeting).now();
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
示例10: unregister
import com.google.appengine.api.users.User; //导入依赖的package包/类
/**
* Unregister a device
* This will not remove a user
*
* @param deviceId The Google Cloud Messaging registration Id to remove
* @param user The Google Authenticated User
*/
@ApiMethod(
name = "users.unregister",
path = "users/unregister",
httpMethod = HttpMethod.POST
)
public void unregister(@Named("deviceId") String deviceId, User user) throws OAuthRequestException, BadRequestException {
UserRecord currentUser = userDAO.getUserRecord(user);
if (currentUser == null) {
throw new OAuthRequestException(Messages.ERROR_AUTH);
}
if (deviceId == null) {
throw new BadRequestException(Messages.ERROR_INVALID_PARAMETERS);
}
for (String id : currentUser.getDevices()) {
if (id.equals(deviceId)) {
// found device - unregister it
currentUser.removeDevice(id);
userDAO.save(currentUser);
return;
}
}
}
示例11: updateUserInformation
import com.google.appengine.api.users.User; //导入依赖的package包/类
/**
* Updates current Tech Gallery user information with user data found on
* Google.
*
* @param user
* Google user
* @param person
* Google Plus person information
* @param tgUser
* Tech Gallery user
*/
private void updateUserInformation(final User user, Person person, TechGalleryUser tgUser) {
String plusEmail = user.getEmail();
String plusPhoto = person.getImage().getUrl();
String plusName = person.getDisplayName();
String currentEmail = tgUser.getEmail();
String currentPhoto = tgUser.getPhoto();
String currentName = tgUser.getName();
if (currentEmail == null || !currentEmail.equals(plusEmail)) {
tgUser.setEmail(plusEmail);
}
if (currentPhoto == null || !currentPhoto.equals(plusPhoto)) {
tgUser.setPhoto(plusPhoto);
}
if (currentName == null || !currentName.equals(plusName)) {
tgUser.setName(plusName);
}
if (tgUser.getGoogleId() == null) {
tgUser.setGoogleId(user.getUserId());
}
}
示例12: doGet
import com.google.appengine.api.users.User; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if (req.getParameter("testing") == null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, this is a testing servlet. \n\n");
Properties p = System.getProperties();
p.list(resp.getWriter());
} else {
UserService userService = UserServiceFactory.getUserService();
User currentUser = userService.getCurrentUser();
if (currentUser != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + currentUser.getNickname());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
}
示例13: PackageDetailPage
import com.google.appengine.api.users.User; //导入依赖的package包/类
/**
* @param mode editing mode
*/
public PackageDetailPage(FormMode mode) {
this.mode = mode;
id = "";
title = "";
url = "";
changelog = "";
icon = "";
description = "";
comment = "";
discoveryURL = "";
discoveryRE = "";
discoveryURLPattern = "";
license = "";
this.tags = new ArrayList<String>();
screenshots = "";
permissions = "";
User u = UserServiceFactory.getUserService().getCurrentUser();
this.params.put("modified", new Date().toString());
this.params.put("modifiedBy", u == null ? "" : u.getEmail());
}
示例14: doGet
import com.google.appengine.api.users.User; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if (req.getParameter("testing") == null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, this is a testing servlet. \n\n");
Properties p = System.getProperties();
p.list(resp.getWriter());
} else {
UserService userService = UserServiceFactory.getUserService();
User currentUser = userService.getCurrentUser();
if (currentUser != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + currentUser.getNickname());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
}
示例15: getEndorsementsByTech
import com.google.appengine.api.users.User; //导入依赖的package包/类
/**
* GET for getting one endorsement.
*
* @throws InternalServerErrorException in case something goes wrong
* @throws OAuthRequestException in case of authentication problem
* @throws NotFoundException in case the information are not founded
* @throws BadRequestException in case a request with problem were made.
*/
@Override
public Response getEndorsementsByTech(String techId, User user)
throws InternalServerErrorException, BadRequestException, NotFoundException,
OAuthRequestException {
final List<Endorsement> endorsementsByTech = endorsementDao.findAllActivesByTechnology(techId);
final List<EndorsementsGroupedByEndorsedTransient> grouped =
groupEndorsementByEndorsed(endorsementsByTech, techId);
final Technology technology = techService.getTechnologyById(techId, user);
techService.updateEdorsedsCounter(technology, grouped.size());
groupUsersWithSkill(grouped, technology);
Collections.sort(grouped, new EndorsementsGroupedByEndorsedTransient());
final ShowEndorsementsResponse response = new ShowEndorsementsResponse();
response.setEndorsements(grouped);
return response;
}