PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/WP7.1/Templates/VB/WPCloud.ACS/WindowsPhoneCloud.Web/Services/RegistrationServices.vb

#
Visual Basic | 73 lines | 46 code | 12 blank | 15 comment | 0 complexity | a6acc290564600a02b3827bf0e4079ff MD5 | raw file
  1. ' ----------------------------------------------------------------------------------
  2. ' Microsoft Developer & Platform Evangelism
  3. '
  4. ' Copyright (c) Microsoft Corporation. All rights reserved.
  5. '
  6. ' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  7. ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  8. ' OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  9. ' ----------------------------------------------------------------------------------
  10. ' The example companies, organizations, products, domain names,
  11. ' e-mail addresses, logos, people, places, and events depicted
  12. ' herein are fictitious. No association with any real company,
  13. ' organization, product, domain name, email address, logo, person,
  14. ' places, or events is intended or should be inferred.
  15. ' ----------------------------------------------------------------------------------
  16. Imports Microsoft.Samples.WindowsPhoneCloud.Web.Models
  17. Imports Microsoft.Samples.WindowsPhoneCloud.Web.Infrastructure
  18. Imports Microsoft.IdentityModel.Claims
  19. Imports System.ServiceModel.Web
  20. Imports System.ServiceModel.Activation
  21. Imports System.ServiceModel
  22. Imports System.Net
  23. Imports System.Globalization
  24. Namespace Services
  25. <ServiceBehavior(IncludeExceptionDetailInFaults:=False), AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
  26. Public Class RegistrationService
  27. Implements IRegistrationService
  28. Private ReadOnly userRepository As IUserRepository
  29. Private ReadOnly userPrivilegesRepository As IUserPrivilegesRepository
  30. Public Sub New()
  31. Me.New(New UserTablesServiceContext(), New UserTablesServiceContext())
  32. End Sub
  33. <CLSCompliant(False)> _
  34. Public Sub New(ByVal userRepository As IUserRepository, ByVal userPrivilegesRepository As IUserPrivilegesRepository)
  35. Me.userRepository = userRepository
  36. Me.userPrivilegesRepository = userPrivilegesRepository
  37. End Sub
  38. Public Function CreateUser(ByVal user As RegistrationUser) As String Implements IRegistrationService.CreateUser
  39. If (user Is Nothing) OrElse String.IsNullOrEmpty(user.Name) OrElse String.IsNullOrEmpty(user.EMail) Then
  40. Throw New WebFaultException(Of String)("Invalid user information.", HttpStatusCode.BadRequest)
  41. End If
  42. Dim identity = TryCast(HttpContext.Current.User.Identity, IClaimsIdentity)
  43. Dim nameIdentifier = identity.Claims.Single(Function(c) c.ClaimType = ClaimTypes.NameIdentifier).Value
  44. Me.userRepository.CreateUser(nameIdentifier, user.Name, user.EMail)
  45. Me.SetUserDefaultUserPrivileges(nameIdentifier)
  46. Return "Success"
  47. End Function
  48. Public Function CheckUserRegistration() As String Implements IRegistrationService.CheckUserRegistration
  49. Dim identity = TryCast(HttpContext.Current.User.Identity, IClaimsIdentity)
  50. Dim nameIdentifier = identity.Claims.Single(Function(c) c.ClaimType = ClaimTypes.NameIdentifier).Value
  51. Return (Me.userRepository.GetUser(nameIdentifier) IsNot Nothing).ToString()
  52. End Function
  53. Private Sub SetUserDefaultUserPrivileges(ByVal userId As String)
  54. Me.userPrivilegesRepository.AddPrivilegeToUser(userId, PrivilegeConstants.TablesUsagePrivilege)
  55. Me.userPrivilegesRepository.AddPrivilegeToUser(userId, PrivilegeConstants.BlobsUsagePrivilege)
  56. Me.userPrivilegesRepository.AddPrivilegeToUser(userId, PrivilegeConstants.QueuesUsagePrivilege)
  57. Me.userPrivilegesRepository.AddPrivilegeToUser(userId, PrivilegeConstants.SqlUsagePrivilege)
  58. Me.userPrivilegesRepository.AddPrivilegeToUser(userId, String.Format(CultureInfo.InvariantCulture, "{0}{1}", "SampleData", PrivilegeConstants.TablePrivilegeSuffix))
  59. End Sub
  60. End Class
  61. End Namespace