Пример #1
0
        public Tuple<int, string, int> register(string email, string password1, string password2)
        {
            int status = 0;
            string message = "";
            int userId = 0;

            if (password1.Length == 0) // check if email entered blank
            {
                status = -1;
                message = "Enter email address!";
            }
            else // check if email is correct
            {
                string expression = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";

                Match match = Regex.Match(email, expression, RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    status = -1;
                    message = "Email address is not correct!";
                }
                else
                {
                    if (password1.Length == 0) // check if password is blank
                    {
                        status = -1;
                        message = "Enter password!";
                    }
                    else
                    {
                        if (password1.Length < 4) // check if password is less than 4 characters
                        {
                            status = -1;
                            message = "Password must be at least 4 characters!";
                        }
                        else
                        {
                            if (password1 != password2) // check if password and retype password are the same
                            {
                                status = -1;
                                message = "Password and retype password must be the same!";
                            }
                            else
                            {
                                Classes.UserInfo ui = new Classes.UserInfo();
                                int UserId = ui.getUserIdByEmail(email);
                                if (UserId != 0) //user registered before
                                {
                                    status = -1;
                                    message = "Email address already registered before!";
                                }
                                else
                                {
                                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                                    SqlCommand sqlCmd = new SqlCommand("sp_register", sqlConn);
                                    sqlCmd.CommandType = CommandType.StoredProcedure;
                                    sqlCmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = email;
                                    sqlCmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password1;
                                    sqlCmd.Parameters.Add("@VCode", SqlDbType.NVarChar).Value = Convert.ToString(Guid.NewGuid());

                                    try
                                    {
                                        sqlConn.Open();
                                        sqlCmd.ExecuteNonQuery();
                                    }
                                    catch
                                    {

                                    }
                                    finally
                                    {
                                        sqlConn.Close();
                                        sqlConn.Dispose();
                                        sqlCmd.Dispose();
                                    }

                                    status = 1;
                                }
                            }
                        }
                    }
                }
            }

            return new Tuple<int, string, int>(status, message, userId);
        }
Пример #2
0
        public Tuple <int, string, int> register(string email, string password1, string password2, int inviteId)
        {
            int    status  = 0;
            string message = "";
            int    userId  = 0;

            if (password1.Length == 0) // check if email entered blank
            {
                status  = -1;
                message = "Enter email address!";
            }
            else // check if email is correct
            {
                string expression = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";

                Match match = Regex.Match(email, expression, RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    status  = -1;
                    message = "Email address is not correct!";
                }
                else
                {
                    if (password1.Length == 0) // check if password is blank
                    {
                        status  = -1;
                        message = "Enter password!";
                    }
                    else
                    {
                        if (password1.Length < 4) // check if password is less than 4 characters
                        {
                            status  = -1;
                            message = "Password must be at least 4 characters!";
                        }
                        else
                        {
                            if (password1 != password2) // check if password and retype password are the same
                            {
                                status  = -1;
                                message = "Password and retype password must be the same!";
                            }
                            else
                            {
                                Classes.UserInfo ui = new Classes.UserInfo();
                                int UserId          = ui.getUserIdByEmail(email);
                                if (UserId != 0) //user registered before
                                {
                                    status  = -1;
                                    message = "Email address already registered before!";
                                }
                                else
                                {
                                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                                    SqlCommand    sqlCmd  = new SqlCommand("sp_register", sqlConn);
                                    sqlCmd.CommandType = CommandType.StoredProcedure;
                                    sqlCmd.Parameters.Add("@Email", SqlDbType.VarChar).Value     = email;
                                    sqlCmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password1;
                                    sqlCmd.Parameters.Add("@VCode", SqlDbType.NVarChar).Value    = Convert.ToString(Guid.NewGuid());
                                    sqlCmd.Parameters.Add("@InviteId", SqlDbType.Int).Value      = inviteId;

                                    //try
                                    //{
                                    sqlConn.Open();
                                    sqlCmd.ExecuteNonQuery();
                                    //}
                                    //catch
                                    //{

                                    //}
                                    //finally
                                    //{
                                    sqlConn.Close();
                                    sqlConn.Dispose();
                                    sqlCmd.Dispose();
                                    //}

                                    status = 1;
                                }
                            }
                        }
                    }
                }
            }

            return(new Tuple <int, string, int>(status, message, userId));
        }