public async Task <HttpResponseMessage> Post(ProjectModel model) { try { await CongratUserIfNeeded(); } catch (Exception e) { Trace.TraceError("Failed to notify user by email: {0}", e); } ProductType product = _productIdExtractor.Get(UserAgent); var project = new DomainProject { UserId = UserId, Name = model.Name, Description = model.Description, Access = model.Access, ProductType = product, ProjectType = model.ProjectType, ProjectSubtype = model.ProjectSubtype, EnableComments = model.EnableComments }; project = await _projectService.AddAsync(project); var responseProject = new Project { Id = project.Id, Description = project.Description, Access = project.Access, Name = project.Name, Created = project.Created, PublicUrl = _projectUriProvider.GetUri(project.Id), ProjectType = project.ProjectType, ProjectSubtype = project.ProjectSubtype, EnableComments = project.EnableComments }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseProject); response.SetLastModifiedDate(project.Modified); return(response); }
public async Task <HttpResponseMessage> Post(RegisterUserModel model) { // Add profile var user = new DomainUser { ApplicationName = AppName, Name = model.UserName, Email = model.Email, Roles = new List <string> { DomainRoles.User }, UserAgent = _productIdExtractor.Get(UserAgent) }; user = await _userService.AddAsync(user); // Set user password await _passwordService.ChangePasswordAsync(user.Id, model.Password); try { await _emailNotificationService.SendRegistrationEmailAsync(user); } catch (Exception e) { Trace.TraceError("Failed to send registration e-mail to {0}: {1}", model.Email, e); } Profile profile = _mapper.Map <DomainUser, Profile>(user); profile.AvatarUrl = _avatarProvider.GetAvatar(user); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, profile); response.SetLastModifiedDate(user.Modified); await _authenticationService.SetUserAsync(user, new TokenData { IdentityProvider = ProviderType.Email }, true); return(response); }
public async Task <ActionResult> ActivateClient(string code) { DomainPendingClient model; try { model = await _pendingClientService.GetAndDeleteAsync(code); } catch (NotFoundException) { return((ActionResult)RedirectToAction("Index", "Home")); } catch (Exception e) { Trace.TraceError("Failed to find client: {0}", e); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } // Add profile var user = new DomainUser { ApplicationName = AppName, Name = model.ContactPerson, Country = model.Country, UserAgent = _productIdExtractor.Get(Request.UserAgent), Email = model.Email, Roles = new List <string> { DomainRoles.Client } }; try { user = await _userService.AddAsync(user); } catch (ConflictException) { return(new HttpStatusCodeResult(HttpStatusCode.Conflict)); } catch (Exception e) { Trace.TraceError("Failed to create user profile for {0}: {1}", model.Email, e); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } // Set user password try { await _passwordService.SetPasswordAsync(user.Id, model.Password, model.PasswordSalt); } catch (Exception e) { Trace.TraceError("Failed to set user {0} password: {1}", user.Id, e); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } // Add company var company = new DomainCompany { Email = model.Email, Name = model.CompanyName, Address = model.Address, ZipCode = model.ZipCode, Phone = model.PhoneNumber, Country = model.Country, Ein = model.Ein, Users = new List <string> { user.Id } }; try { await _companyService.AddAsync(company); } catch (Exception e) { Trace.TraceError("Failed to create company for user {0}: {1}", user.Id, e); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } // Authenticate await _authenticationService.SetUserAsync(user, null, true); return(RedirectToRoute(RouteNames.ClientSubscriptions)); }
public async Task <HttpResponseMessage> Post(SessionIpModel model) { ITokenDataExtractor tokenDataExtractor = _tokenDataExtractorFactory.CreateTokenDataExtractor(model.Type); TokenData tokenData; try { tokenData = tokenDataExtractor.Get(model); } catch (BadRequestException) { ModelState.AddModelError("Token", ResponseMessages.AccountsInvalidToken); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } // Return result DomainUser user = null; try { user = await _userService.FindByIdentityAsync(tokenData.IdentityProvider, tokenData.UserIdentifier); } catch (NotFoundException) { } // Try to find user by email if (user == null && !string.IsNullOrEmpty(tokenData.Email)) { try { user = await _userService.FindByEmailAsync(tokenData.Email); } catch (NotFoundException) { } // Add ip memebership to user if (user != null) { await _userService.AddMembersipAsync(user.Id, tokenData); } } var httpStatusCode = HttpStatusCode.OK; // Check whether registration is required if (user == null) { var profileData = new DomainUser { ApplicationName = AppName, Name = tokenData.Name, Email = tokenData.Email, UserAgent = _productIdExtractor.Get(UserAgent), Roles = new List <string> { DomainRoles.User }, Memberships = new List <UserMembership> { new UserMembership { IdentityProvider = tokenData.IdentityProvider, UserIdentifier = tokenData.UserIdentifier, } } }; user = await _userService.AddAsync(profileData); // Send registration e-mail try { await _emailNotificationService.SendRegistrationEmailAsync(user); } catch (Exception e) { Trace.TraceError("Failed to send registration email to address {0} for user {1}: {2}", user.Email, user.Id, e); } // Send notification into social network ISocialNetworkNotifier notifier = _notificationFactory.GetNotifier(tokenData.IdentityProvider); if (notifier != null) { try { await notifier.SendWelcomeMessageAsync(user, tokenData); } catch (BadGatewayException) { } catch (Exception e) { Trace.TraceError("Failed to send welcome message to user {0}: {1}", user.Id, e); } } httpStatusCode = HttpStatusCode.Created; } var token = await _authenticationService.SetUserAsync(user, tokenData, true); return(Request.CreateResponse(httpStatusCode, new AuthenticationTokenModel { Token = token })); }
public async Task SendFirstProjectEmail(string userId, string userAgent) { if (!_settings.EmailNotifications) { return; } string template; EmailTemplate templateId; ProductType product = _productIdExtractor.Get(userAgent); switch (product) { case ProductType.ImageShack: template = PortalResources.UserRegistrationImageshack; templateId = EmailTemplate.FirstProjectExtension; break; case ProductType.CicIPad: case ProductType.CicMac: case ProductType.CicPc: template = PortalResources.ProjectFirstCic; templateId = EmailTemplate.FirstProjectCic; break; case ProductType.TaggerAndroid: case ProductType.TaggerIPhone: template = PortalResources.ProjectFirstTagger; templateId = EmailTemplate.FirstProjectOtherProducts; break; case ProductType.Standalone: template = PortalResources.UserRegistration; templateId = EmailTemplate.Registration; break; default: return; } bool emailAlreadySendOnce = await CheckEmailBeenSend(userId, templateId); if (emailAlreadySendOnce) { return; } DomainUser user = await _userService.GetAsync(userId); if (user == null || string.IsNullOrEmpty(user.Email)) { return; } var email = new SendEmailDomain { Body = string.Format(template, user.Name), Address = _settings.EmailAddressInfo, DisplayName = Emails.SenderDisplayName, Subject = Emails.SubjectFirstTag, Emails = new List <string> { user.Email }, UserId = userId, Template = templateId }; await _emailSenderService.SendAndLogEmailAsync(email); }