コード例 #1
0
        public string Register(string email, string password, string networkJoinCode = null)
        {
            if (Request != null)
            {
                if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
                {
                    return null;
                }
            }
            try
            {
                CommunicationManager communicationManager = new CommunicationManager();
                string userName = email.Substring(0, email.IndexOf('@'));
                userName = userName.Replace("+", "");
                RegisterModel model = new RegisterModel { Email = email, UserName = userName, Password = password, ConfirmPassword = password };
                if (ValidationEngine.ValidateEmail(model.Email) != ValidationEngine.Success)
                {
                    return AddErrorHeader("Invalid Email", 1);
                }
                if (!userManager.CheckDuplicateEmail(model.Email))
                {
                    return AddErrorHeader("A user with that email already exists in our database", 1);
                }
                if (ValidationEngine.ValidateUsername(model.UserName) != ValidationEngine.Success)
                {
                    return AddErrorHeader(ValidationEngine.ValidateUsername(model.UserName), 1);
                }
                if (!userManager.CheckDuplicateUsername(model.UserName))
                {
                    return AddErrorHeader("A user with that username already exists in our database", 1);
                }
                if (ValidationEngine.ValidatePassword(model.Password) != ValidationEngine.Success)
                {
                    return AddErrorHeader(ValidationEngine.ValidateUsername(model.Password), 1);
                }
                if (model.Password != model.ConfirmPassword)
                {
                    return AddErrorHeader("Password fields do not match", 1);
                }
                if (ModelState.IsValid)
                {
                    User newUser = model.toUser();
                    newUser.profileURL = newUser.userName;

                    newUser = userManager.CreateUser(newUser, model.Password);

                    userManager.ActivateUser(newUser, true);
                    //communicationManager.SendVerificationMail(userManager.GetProviderUserKey(newUser), newUser.userName, newUser.email);

                    if (networkJoinCode != null)
                    {
                        NetworkManager nm = new NetworkManager();
                        Network network = nm.GetNetworkByIdentifier(networkJoinCode);
                        if (network != null)
                        {
                            string[] emailArray = { email };
                            nm.AddNetworkUsers(network, emailArray);
                        }
                    }
                    userManager.SendVerifyEmail(email);

                    AuthenticaitonEngine authEngine = new AuthenticaitonEngine();
                    string token = authEngine.logIn(newUser.id, newUser.userName);
                    JsonModels.RegisterResponse rr = new JsonModels.RegisterResponse();
                    rr.userId = newUser.id;
                    rr.token = token;
                    return AddSuccessHeader(Serialize(rr));
                }
                else
                {
                    return AddErrorHeader("User Model Not Valid", 1);
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex.ToString());
                return AddErrorHeader("Something went wrong while creating this user", 1);
            }
        }
コード例 #2
0
 public string JoinNetwork(string networkJoinCode, string token)
 {
     if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))  //This is a preflight request
     {
         return null;
     }
     try
     {
         NetworkManager networkManager = new NetworkManager();
         int userId = authenticationEngine.authenticate(token);
         if (userId < 0)
         {
             return AddErrorHeader("Not Authenticated", 2);
         }
         Network network = networkManager.GetNetworkByIdentifier(networkJoinCode);
         User user = userManager.GetUser(userId);
         if (network != null)
         {
             string[] email = { user.email };
             networkManager.AddNetworkUsers(network, email);
             return GetUserModel(userId, token);
         }
         else
         {
             return AddErrorHeader("The network join code is invalid", 1);
         }
     }
     catch (Exception ex)
     {
         logAccessor.CreateLog(DateTime.Now, "NetworkController - JoinNetwork", ex.StackTrace);
         return AddErrorHeader("something went wrong while joining this network", 1);
     }
 }