/// <summary> /// Get the current user. /// </summary> /// <param name="request">Request.</param> /// <returns>the current user</returns> public object Get(UserGetCurrentRequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/user/current GET")); UserTep user = UserTep.FromId(context, context.UserId); try { user.PrivateSanityCheck();//we do it here, because we do not want to do on each Load(), and we are sure users always pass by here }catch (Exception e) { context.LogError(this, e.Message, e); } result = new WebUserTep(context, user, false); try{ var cookie = DBCookie.LoadDBCookie(context, context.GetConfigValue("cookieID-token-access")); result.Token = cookie.Value; TimeSpan span = cookie.Expire.Subtract(DateTime.UtcNow); result.TokenExpire = span.TotalSeconds; }catch (Exception) {} context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Post the specified request. /// </summary> /// <param name="request">Request.</param> public object Post(UserCreateRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebUserTep result; try{ context.Open(); UserTep user = (request.Id == 0 ? null : UserTep.FromId(context, request.Id)); user = request.ToEntity(context, user); if (request.Id != 0 && context.UserLevel == UserLevel.Administrator) { user.AccountStatus = AccountStatusType.Enabled; } else { user.AccountStatus = AccountStatusType.PendingActivation; } user.IsNormalAccount = true; user.Level = UserLevel.User; user.Store(); context.LogInfo(this, string.Format("/user POST Id='{0}'", user.Id)); context.LogDebug(this, string.Format("User '{0}' has been created", user.Username)); result = new WebUserTep(context, user); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Update the specified user. /// </summary> /// <param name="request">Request.</param> /// <returns>the user</returns> public object Put(UserUpdateRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/user PUT Id='{0}'", request.Id > 0 ? request.Id + "" : request.Identifier)); UserTep user = (request.Id == 0 ? (!string.IsNullOrEmpty(request.Identifier) ? UserTep.FromIdentifier(context, request.Identifier) : null) : UserTep.FromId(context, request.Id)); if (context.UserId != user.Id && context.AccessLevel != EntityAccessLevel.Administrator) { throw new Exception("Action not allowed"); } var level = user.Level; user = request.ToEntity(context, user); user.Level = level;//we can only change the level from the dedicated request (admin only) user.Store(); context.LogDebug(this, string.Format("User '{0}' has been updated", user.Username)); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Put(UpdateProfileFromRemoteTep request) { WebUserTep result = null; var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); context.Open(); var usr = UserTep.FromIdentifier(context, request.Identifier); try { usr.LoadProfileFromRemote(); result = new WebUserTep(context, usr); }catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); } context.Close(); return(result); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(UserGetCurrentSSORequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/user/current/sso GET")); UserTep user = UserTep.FromId(context, context.UserId); //user.FindTerradueCloudUsername(); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Post(UserCurrentCreateSSORequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/user/current/sso POST")); UserTep user = UserTep.FromId(context, context.UserId); user.CreateSSOAccount(request.Password); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(UserGetSSORequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/user/sso/{{Id}} GET Id='{0}'", request.Identifier)); UserTep user = UserTep.FromIdentifier(context, request.Identifier); //user.FindTerradueCloudUsername(); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(UserGetRequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/user/{{Id}} GET Id='{0}'", request.Id)); UserTep user = UserTep.FromId(context, request.Id); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Put(UserUpdateSSORequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/user/sso PUT Identifier='{0}',T2Username='******'", request.Identifier, request.T2Username)); UserTep user = UserTep.FromIdentifier(context, request.Identifier); user.TerradueCloudUsername = request.T2Username; user.StoreCloudUsername(); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Post(UserAddTransactionRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/transaction/user POST Identifier='{0}', Balance='{1}'", request.Identifier, request.Balance)); UserTep user = UserTep.FromIdentifier(context, request.Identifier); user.AddAccountingTransaction(request.Balance, (TransactionKind)request.Kind); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Put(UserUpdateAdminRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/user/admin PUT Id='{0}'", request.Id)); UserTep user = (request.Id == 0 ? null : UserTep.FromId(context, request.Id)); user.Level = request.Level; user.Store(); context.LogDebug(this, string.Format("Level of user '{0}' has been updated to Level {1}", user.Username, request.Level)); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Delete(UserDeleteApiKeyRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/user/key DELETE Id='{0}'", context.UserId)); UserTep user = UserTep.FromId(context, context.UserId); user.ApiKey = null; user.Store(); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Put(UserUpdateStatusRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/user/status PUT Id='{0}',Status='{1}'", request.Id > 0 ? request.Id + "" : request.Identifier, request.AccountStatus)); UserTep user = (request.Id == 0 ? (!string.IsNullOrEmpty(request.Identifier) ? UserTep.FromIdentifier(context, request.Identifier) : null) : UserTep.FromId(context, request.Id)); user.AccountStatus = request.AccountStatus; user.Store(); context.LogDebug(this, string.Format("Status of user '{0}' has been updated to {1}", user.Username, request.AccountStatus)); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }