public ApiToken Token(string code, string provider) { var externalUser = loginHelper.GetExternalUser(provider, code); ApiToken token = null; if (externalUser != null) { var apiUser = usersLogic.GetApiUserByExternalIdAndProvider(externalUser.ExternalId, externalUser.Provider) ?? usersLogic.CreateUser(externalUser.ExternalId, externalUser.Provider); token = usersLogic.CreateTokenForApiUser(apiUser); } return(token); }
private void CreateUser() { UsersLogic usersLogic = new UsersLogic(); if (FirstName.Length == 0) { SnackbarMessageQueue.Enqueue("First Name Required"); } else if (LastName.Length == 0) { SnackbarMessageQueue.Enqueue("Last Name Required"); } else if (!usersLogic.BirthDayValidator.Validate(BirthDay)) { SnackbarMessageQueue.Enqueue("Invalid BirthDay"); } else if (!usersLogic.EmailValidator.Validate(Email)) { SnackbarMessageQueue.Enqueue("Invalid Email"); } else if (!usersLogic.PasswordStrengthValidator.Validate(Password)) { SnackbarMessageQueue.Enqueue("Password is not strong enough. Min 6 charaters required."); } else if (Password != PasswordValidation) { SnackbarMessageQueue.Enqueue("Passwords Don't Match"); } else { var res = usersLogic.CreateUser(FirstName, LastName, BirthDay, Email, Password); switch (res) { case UsersLogic.CreationStatus.Created: SnackbarMessageQueue.Enqueue("Successfull created user!", "Sign In", // TODO: BAD MVVM () => { Flipper.FlipCommand.Execute(null, null); }); break; case UsersLogic.CreationStatus.UserWithThisEmailAlreadyExists: SnackbarMessageQueue.Enqueue("There already exists a user with this email."); break; } } }
private ActionResult Authenticate(string code, string provider, string redirectUrl) { ActionResult result; var externalUser = loginHelper.GetExternalUser(provider, code); if (externalUser != null) { var apiUser = usersLogic.GetApiUserByExternalIdAndProvider(externalUser.ExternalId, externalUser.Provider); if (apiUser != null && apiUser.Name != null) { if (String.IsNullOrEmpty(redirectUrl)) { redirectUrl = Url.Action("Index", "Patterns"); } result = new RedirectResult(redirectUrl); } else { apiUser = usersLogic.CreateUser(externalUser.ExternalId, externalUser.Provider); var registrationUrl = Url.Action("Register"); result = new RedirectResult(registrationUrl); } var token = usersLogic.CreateTokenForApiUser(apiUser); if (token != null) { HttpContext.Response.Cookies.Add(new HttpCookie("Token", token.Id.ToString()) { Expires = token.ExpirationTime }); } } else { result = RedirectToAction("Index", "Patterns"); } return(result); }
//POST v1/users public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel request) { if (request == null) { ModelState.AddModelError("", "Request parameters not entered."); } if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(r => r.Errors).Select(error => error.ErrorMessage).ToList(); return(Content((HttpStatusCode)422, new { errors })); } try { var user = await _userLogic.CreateUser(Mapper.Map <Users>(request)); return(Created("", Mapper.Map <UserResponseItem>(user))); } catch (Exception ex) { return(InternalServerError()); } }