Search in sources :

Example 16 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class AccessTokenDataUtil method newUserAccessToken.

public static AccessToken newUserAccessToken(HttpServletRequest request) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    AccessToken accessToken = dataAccessor.newAccessToken();
    accessToken.setUserId(0L);
    accessToken.setDeviceLocation(request.getHeader("X-AppEngine-City"), request.getHeader("X-AppEngine-Region"), request.getHeader("X-AppEngine-Country"));
    accessToken.setDeviceUserAgent(request.getHeader("User-Agent"));
    accessToken.setExpiry(new Date(new Date().getTime() + MAX_EXPIRY_MILLIS));
    accessToken.setCreationDate(new Date());
    accessToken = dataAccessor.createOrUpdateAccessToken(accessToken);
    return accessToken;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) AccessToken(com.pratilipi.data.type.AccessToken) Date(java.util.Date)

Example 17 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class TagsApi method addTags.

@Post
public GenericResponse addTags(PostRequest request) throws InsufficientAccessException {
    // Security Hack
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    if (accessToken.getUserId() != 5073076857339904L) {
        Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "AccessToken : " + accessToken.getId());
        Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "User Id : " + accessToken.getUserId());
        throw new InsufficientAccessException();
    }
    Gson gson = new Gson();
    // Creating TagData object.
    TagData tagData = gson.fromJson(gson.toJson(request), TagData.class);
    tagData = TagDataUtil.saveTag(tagData);
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) AccessToken(com.pratilipi.data.type.AccessToken) Gson(com.google.gson.Gson) TagData(com.pratilipi.data.client.TagData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Post(com.pratilipi.api.annotation.Post)

Aggregations

AccessToken (com.pratilipi.data.type.AccessToken)17 DataAccessor (com.pratilipi.data.DataAccessor)8 Author (com.pratilipi.data.type.Author)8 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)5 Date (java.util.Date)5 UserAuthor (com.pratilipi.data.type.UserAuthor)3 UserPratilipi (com.pratilipi.data.type.UserPratilipi)3 Post (com.pratilipi.api.annotation.Post)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 AuditLog (com.pratilipi.data.type.AuditLog)2 Pratilipi (com.pratilipi.data.type.Pratilipi)2 AccessTokenEntity (com.pratilipi.data.type.gae.AccessTokenEntity)2 Gson (com.google.gson.Gson)1 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)1 AuthorData (com.pratilipi.data.client.AuthorData)1 PratilipiData (com.pratilipi.data.client.PratilipiData)1 TagData (com.pratilipi.data.client.TagData)1 UserData (com.pratilipi.data.client.UserData)1 Comment (com.pratilipi.data.type.Comment)1 Vote (com.pratilipi.data.type.Vote)1