Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. public SignUp2ViewModel()
  2. {
  3. SendInfoAWSCommand = new Command(async ()=> await SendInfoAWS());
  4.  
  5. }
  6.  
  7. public Command SendInfoAWSCommand { get; }
  8.  
  9. const string AppClientID = "sum stuff";
  10. const string PoolID = " sum place";
  11. static Amazon.RegionEndpoint Region = Amazon.RegionEndpoint.USWest2;
  12.  
  13.  
  14.  
  15.  
  16. async Task SendInfoAWS()
  17. {
  18. IsBusy = true;
  19. await Task.Delay(500);
  20. AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), Region);
  21. SignUpRequest signUpRequest = new SignUpRequest()
  22. {
  23. ClientId = AppClientID,
  24. Username = usuario,
  25. Password = senha
  26. };
  27. List<AttributeType> attributes = new List<AttributeType>()
  28. {
  29. new AttributeType(){Name = "email", Value = email }
  30. };
  31. signUpRequest.UserAttributes = attributes;
  32. try
  33. {
  34. SignUpResponse result = await provider.SignUpAsync(signUpRequest);
  35. }
  36. catch (Exception e)
  37. {
  38. IsBusy = false;
  39. await Application.Current.MainPage.DisplayAlert("Error", ("Contact has NOT been saved" + e.Message + " "), "OK");
  40. return;
  41. }
  42.  
  43. IsBusy = false;
  44.  
  45. await Application.Current.MainPage.DisplayAlert("Save", "Contact has been saved", "OK");
  46. }
  47.  
  48.  
  49. string email;
  50. string usuario;
  51. string senha;
  52. bool isBusy = false;
  53.  
  54.  
  55.  
  56. public string Email
  57. {
  58. get
  59. {
  60. return email;
  61. }
  62. set
  63. {
  64. email = value;
  65. OnPropertyChanged();
  66. }
  67. }
  68. public string Usuario
  69. {
  70. get
  71. {
  72. return usuario;
  73. }
  74. set
  75. {
  76. usuario = value;
  77. OnPropertyChanged();
  78. }
  79. }
  80. public string Senha
  81. {
  82. get
  83. {
  84. return senha;
  85. }
  86. set
  87. {
  88. senha = value;
  89. OnPropertyChanged();
  90. }
  91. }
  92.  
  93. public bool IsBusy
  94. {
  95. get { return isBusy; }
  96. set
  97. {
  98. isBusy = value;
  99.  
  100. OnPropertyChanged();
  101. SendInfoAWSCommand.ChangeCanExecute();
  102. }
  103. }
  104.  
  105.  
  106. public event PropertyChangedEventHandler PropertyChanged;
  107. void OnPropertyChanged([CallerMemberName] string name = "")
  108. {
  109. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116. }
  117.  
  118.  
  119. }
  120.  
  121. public SignInViewModel()
  122. {
  123. SendInfoAWSCommand = new Command(async () => await SendInfoAWS());
  124.  
  125. }
  126.  
  127. public Command SendInfoAWSCommand { get; }
  128.  
  129. static string usuario;
  130. static string senha;
  131. static bool isBusy = false;
  132.  
  133. public string Usuario
  134. {
  135. get
  136. {
  137. return usuario;
  138. }
  139. set
  140. {
  141. usuario = value;
  142. OnPropertyChanged();
  143. }
  144. }
  145. public string Senha
  146. {
  147. get
  148. {
  149. return senha;
  150. }
  151. set
  152. {
  153. senha = value;
  154. OnPropertyChanged();
  155. }
  156. }
  157. public bool IsBusy
  158. {
  159. get { return isBusy; }
  160. set
  161. {
  162. isBusy = value;
  163.  
  164. OnPropertyChanged();
  165. SendInfoAWSCommand.ChangeCanExecute();
  166. }
  167. }
  168.  
  169. const string AppClientID = "same place";
  170. const string PoolID = " other suff";
  171. static Amazon.RegionEndpoint Region = Amazon.RegionEndpoint.USWest2;
  172.  
  173. public event PropertyChangedEventHandler PropertyChanged;
  174. void OnPropertyChanged([CallerMemberName] string name = "")
  175. {
  176. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  177. }
  178.  
  179. public async Task SendInfoAWS()
  180. {
  181. IsBusy = true;
  182.  
  183. await Task.Delay(500);
  184.  
  185. AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), Region);
  186. CognitoUserPool userPool = new CognitoUserPool(PoolID, AppClientID, provider);
  187. CognitoUser user = new CognitoUser(usuario, AppClientID, userPool, provider);
  188. InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
  189. {
  190. Password = senha
  191. };
  192. AuthFlowResponse authFlowResponse = null;
  193.  
  194. try
  195. {
  196. authFlowResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
  197.  
  198. }
  199. catch (Exception e)
  200. {
  201. isBusy = false;
  202. await Application.Current.MainPage.DisplayAlert("Login Failed", (" " + e.Message + " "), "OK");
  203. return;
  204. }
  205.  
  206. IsBusy = false;
  207. GetUserRequest getUserRequest = new GetUserRequest();
  208. getUserRequest.AccessToken = authFlowResponse.AuthenticationResult.AccessToken;
  209. await Application.Current.MainPage.DisplayAlert("Login Successful", "Welcome!", "OK");
  210. }
  211.  
  212.  
  213.  
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement